Out-of-bounds pointers

Walter Murray walter at hpclwjm.HP.COM
Thu Oct 5 06:18:59 AEST 1989


Ed Gould:

> Is the following code conformant?  It's clear that it's not legal to
> dereference the pointer in its "illegal" state, but is the p++ line
> guaranteed to return it to a valid value?

Henry Spencer:

> The effect of the `p--' line is undefined, so all bets are off.

Doug Gwyn:

> It's not even "legal" to compute an invalid address, whether or not
> it is dereferenced.

I agree with Henry and Doug (generally a safe bet!), but I do think
the wording of 3.3.6 might be misleading:  "Unless both the pointer
operand and the result point to elements of the same array object,
or the pointer operand points one past the last element of an array
object and the result points to an element of the same array object,
the behavior is undefined if the result is used as an operand of
the unary * operator."  Doesn't this imply rather strongly that it
IS legal to compute an invalid address, as long as it isn't
dereferenced?

Walter Murray
walter at hpda.HP.COM
---



More information about the Comp.std.c mailing list