|
![](/i/fill.gif) |
Warp wrote:
> 'union' in C is basically a construct which exists to save some bytes
> of memory in some rare circumstances.
I have also seen it used for typecasting, but nowadays I think casting the
address of the thing to the "wrong" pointer type and then indirecting it
gets used more. I.e.; { long x = ...; float f = *(float*)&x; }
> As for removing null pointers, that would present problems of its own.
> Null pointers in languages like C, C++ and Java are often used for useful
> things.
I think the way to think of it is that a pointer that can be null is a
different type than a pointer that can't be null, and you have to do the
equivalent of a dynamic_cast<> from a nullable pointer to a non-nullable
pointer before you can indirect thru it.
Of course, if your language wasn't lame, you'd be able to just say
if (x != null) y = *x;
and the compiler would use typestate or something to let that go, whereas
without the "if (x != null)" on the front, it would complain that maybe *x
is indirecting thru null.
The problem isn't that pointers might be null. The problem is that someone
might indirect thru a null (or otherwise uninitialized) pointer without
knowing it.
> In Objective-C you usually don't have to check for null pointers.
That's the other way to handle it. Or to throw an exception which you can
catch. The Obj-C way certainly sounds more ... PHPish. ;-)
--
Darren New, San Diego CA, USA (PST)
Serving Suggestion:
"Don't serve this any more. It's awful."
Post a reply to this message
|
![](/i/fill.gif) |