keyongtech


  keyongtech > vc.* > vc.language > 07/2008

 #16  
07-29-08, 12:06 AM
Ben Voigt [C++ MVP]
>> 2. Don't need to cast to void*
>>
>> void* p = iA;

>
> My book is suggesting to explicitly cast all changes of types (because
> apparently casting is a major source of bugs and to have them
> explicitly stated helps debugging)


That's very bad advice, because it interferes with static code analysis and
compiler warnings.

Use casts only when the default conversion rules don't work, and use the new
C++ named casts instead of C-style casts to be able to find casts with a
textual search of the code.
 #17  
07-29-08, 08:45 AM
Fil
"Ben Voigt [C++ MVP]" wrote:

> > My book is suggesting to explicitly cast all changes of types (because
> > apparently casting is a major source of bugs and to have them
> > explicitly stated helps debugging)

>
> That's very bad advice, because it interferes with static code analysis and
> compiler warnings.
>
> Use casts only when the default conversion rules don't work, and use the new
> C++ named casts instead of C-style casts to be able to find casts with a
> textual search of the code.
>


Ok
Thank you

Similar Threads
reinterpret_cast

Per Stroustrup C++ Glossary ([..] glossary.html#Greinterpret_cast) reinterpret_cast - a type conversion operation that reinterprets the raw memory of an object as a value of...

reinterpret_cast

I am trying to understand reinterpret_cast,here is what i tried, #include<iostream> #include<cstdio> using namespace std; int main() { int x=1; int* y=&x;

Exercise & Sell - why not just Exercise vested stock options?

[Money Deluxe 2004] Of a grant for 100 shares that have now vested fully, I choose to sell a certain portion of it, say 50 shares, and hold on to the remaining 50. To...

reinterpret_cast ?

I have this case: DWORD dwSize = 100; Base64Decode(, , , &dwSize); Since 4th param of Windows/ATL Base64Decode() func is of "int*" type, I need to apply some cast. Is this...

Using reinterpret_cast

I am using a C library in my C++ program. I open a file for reading in binary populating a char buffer. I pass this buffer to the C funtion. When it is done I write the...


All times are GMT. The time now is 09:09 PM. | Privacy Policy