 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Alex Vinokur Guest
|
|
| Back to top |
|
 |
Robert J. Hansen Guest
|
Posted: Tue Jun 20, 2006 9:10 am Post subject: Re: Casting (void*)&foo |
|
|
Alex Vinokur wrote:
| Quote: | Is this approach safe?
|
Absolutely, for peculiar meanings of "safe". Some good rules of thumb:
* A C-style cast is never safe.
* A C-style cast to a void* is especially never safe.
* A C-style cast that disregards a const qualifier is ridiculously
especially never safe.
* And a C-style cast that tries to...
This approach is almost gratuitously unsafe. Please don't use this in
any real-world code. There are certainly some specific instances where
this approach is harmless, but in the main, this approach is just full
of all different kinds of things to avoid. |
|
| Back to top |
|
 |
werasm Guest
|
Posted: Wed Jun 21, 2006 9:10 am Post subject: Re: Casting (void*)&foo |
|
|
Frederick Gotham wrote:
| Quote: |
The one major advantage of C style casts is they're not as laborious to
type out:
(int)val
Versus:
static_cast<int>(val)
|
Hmmm, given. One major advantage of C++ style casts is that they're
easy to find when looking for the source of your mistakes. Furthermore,
they concise. They have responsibility. They give certain guarantees.
An erroneous static_cast would fail to compile. C style casts compile
regardless of human error, and all humans make errors. For that reason,
I'll rather type .25 secs longer than look for a hard to find bug.
Regards,
Werner
| Quote: |
--
Frederick Gotham |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|