Invalid Pointers (was Re: Referencing NULL pointers)
Jonathan I. Kamens
jik at athena.mit.edu
Fri Jul 21 13:00:39 AEST 1989
In article <34785 at bu-cs.BU.EDU> bzs at bu-cs.BU.EDU (Barry Shein) writes:
>A perfectly good solution is:
>
> struct foobar no_foobar;
> #define NO_FOOBAR (&no_foobar)
>
>being as no_foobar will be the only thing assigned this address it is
>unique and solves your problem.
struct foobar no_foobar;
#define NO_FOOBAR (&no_foobar)
struct foobar foo_array[50];
struct foobar *ptr;
...
ptr = &foo_array[0];
ptr = ptr - 1;
Now, the last line above is obviously not something that should be
encouraged :-), but fencepost errors of that type happen commonly
inside loops et al. You can't assume that just because you've
allocated a particular spot in memory be declaring a variable to sit
in that spot, nothing else will ever try to access that spot.
The already-mentioned assignment of NO_FOOBAR to 0 is a better
solution.
Jonathan Kamens USnail:
MIT Project Athena 432 S. Rose Blvd.
jik at Athena.MIT.EDU Akron, OH 44320
Office: 617-253-4261 Home: 216-869-6432
More information about the Comp.unix.wizards
mailing list