On Monday 04 August 2003 21:40, Sebastian Kapfer wrote:
> > // change the way it is accessed to prove a point int * p_b = (int *)
> > p_a;
>
> Ouch.
Try this in /usr/src/linux/kernel
$ grep *\) *.c
>
> > // p_a and p_b point to the same block of dyn. allocated memory;
>
> Do they?
They do. My app would be broken from the start if I could not rely on this
capability. This style of type conversion is covered in elementary C++ books
by Bjarne. It's not unusual. You must be aware of what you are doing when
you do a type conversion. Portability is a concern. I am limiting my app to
Intel 32 bit Linux. Screw everything else.
> Watch out for inheritance, user-defined casting operators and
> other funny stuff. C++ adds a few new meanings to the () casting syntax.
> In general, your assumption is _wrong_.
I have no user defined casting operators or funny stuff. I'm no fan of
overloading.
>
> One should also note that the C-style casting operator is considered bad
> style in C++. The "politically correct" way to rewrite your example is
>
> int *p_b = reinterpret_cast<int *>(p_a);
By whom? Your example is nowhere to be found in my C++ books by Bjarne. So
you are saying that Bjarne promotes bad style in his books? Why not tell him:
http://www.research.att.com/~bs/homepage.html
Besides, reinterpret_cast is probably a template function doing this:
return ((T) x); // type conversion using cast
>
> That way, you're clearly stating the intent of the cast. It is up to your
> compiler what it makes of this statement; the C++ standard doesn't cover
> such abuse.
Language experts sure get their shorts knotted up over simple questions.
I've known some killer programmers and none of them have quoted a language
specification in conversation. That was way over the top. That stuff is for
compiler writers, not application programmers. I did not start a knowledge
contest. If I did inadvertently, then you win. I just wanted to discuss a
problem with others of similar interest and try to learn something. I really
don't care if my code style is bad, abusive, or politically incorrect. I
just want to make a couple of bucks and make something useful.
--
Mike Mueller