James Giles writes:
> I'm just curious why pointers to zero-sized objects
> is allowed at all. Is there a value I'm not seeing?
Oh. They are very useful. Just like zero trip-count DO loops and
zero-length strings are useful. Sometimes you naturally end up with
zero-sized things in a general-case algorithm. If the language
doesn't allow it, then you need special case code. Happens all
the time.
To just pull something quick and unspecific out of my hat: Perhaps
I have an array of "things". I now have categories that the "things"
might fall into and want to make arrays for the "things" in each
of those categories. It is quite natural that in some particular
case, I might have no elements in some category. That naturally
ends up as a zero-sized array. This kind of thing happens to me
a lot. And I can do things like loop through all of the (zero)
elements of the array - it all tends to work "naturally"...that
is as long as I don't ask about association between two of them.
Of course, perhaps you are asking more specifically about the pointer
part. I'll just say that if its useful to be able to have an object,
I find it useful to be able to have pointers to the object. If thats
what you are questioning, then count me out of the discussion. I will
*NOT* enter yet another discussion with you about the various "evils"
of pointers. You are welcome to your opinions on that. I'll not
try to "convert" you to my religion.
Luckily, I don't typically need to worry about whether or not two
zero-sized pointers are associated with each other or not. To the
extent that I likely cared, neither always true nor always false would
be the right answer for me. I'd just have to use some separate flag
to keep track of the association. Luckily, thats doable for the
things I'd be likely to use it for.
--
Richard Maine
[log in to unmask]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|