From: Richard Maine <[log in to unmask]> Wrote:
>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.
Ok. That makes more sense. It isn't the kind of think I'd use
poinetrs to so (not by choice), but in the absence of reallocate
it might be the most reasonable way. I've not done things like
that before myself though.
For your later example of having categories of things, some of
the categories being empty, I'd use explicit counts of the size of
each category. Those counts would be the loop trip counts
and/or the subscript limits in whole array operations so everything
would continue to work normally even when the counts were zero.
And, I'd not be dependent on any implementation's unusual notions
about what properties to give a zero-sized object (pointer or not).
In fact, I'd probably put all the things (whatever they are) into a
single non-zero-sized array with the counts specifying subranges of
that array holding each category. That's what you'd be doing with the
pointers too. I'd just be doing it explicitly so that both I and the
compiler can easily tell whether aliased references were occuring
(they're usually not).
--
J. Giles
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|