When should a type cast not be used?

A type cast should not be used to override a const or volatile declaration. Overriding these type modifiers can cause the program to fail to run correctly. A type cast should not be used to turn a pointer to one type of structure or data type into another. In the rare events in which this action is beneficial, using a union to hold the values makes the programmer’s intentions clearer.  

Showing Answers 1 - 6 of 6 Answers

kbjarnason

  • Jul 2nd, 2010
 

And it should never, ever, EVER be used to cast the return from malloc, at least in C (and if you're using C++, why are you using malloc?)

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions