Indeterminate Pointer Value for One-Past

S

Shao Miller

int main(void) {
char *cp;
{
char ca[10];
/* Point to one-past 'ca' array object. */
cp = ca + sizeof ca;
}
/* Indeterminate pointer value in the test below? */
if (cp)
cp = (char *)0;
return 0;
}
 
K

Keith Thompson

Shao Miller said:
int main(void) {
char *cp;
{
char ca[10];
/* Point to one-past 'ca' array object. */
cp = ca + sizeof ca;
}
/* Indeterminate pointer value in the test below? */

Yes. Is there some reason you think it wouldn't be?
if (cp)
cp = (char *)0;
return 0;
}

C99 6.2.4p2 says:

The value of a pointer becomes indeterminate when the object it
points to reaches the end of its lifetime.

Strictly speaking cp didn't point to an object, but it's reasonable
to assume that 6.2.p2 is intended to apply anyway. I suppose it
could be re-worded to cover this case, but I'm not convinced it
would be worth it.
 
S

Shao Miller

Keith said:
Shao Miller said:
int main(void) {
char *cp;
{
char ca[10];
/* Point to one-past 'ca' array object. */
cp = ca + sizeof ca;
}
/* Indeterminate pointer value in the test below? */

Yes. Is there some reason you think it wouldn't be?

No. It does mean that somebody writing an implementation which
purposefully changes a pointer value to something indeterminate (such as
a trap representation) at the end of the pointed-to object's lifetime
has to note this case.

If this same implementation happened to land the pointer on an
immediately adjacent object whose lifetime is not the same, do we make
the pointer value indeterminate or not? Most likely we do wish to,
since the reality of the adjacent object should not be relied upon by
the programmer.
C99 6.2.4p2 says:

The value of a pointer becomes indeterminate when the object it
points to reaches the end of its lifetime.

Strictly speaking cp didn't point to an object, but it's reasonable
to assume that 6.2.p2 is intended to apply anyway. I suppose it
could be re-worded to cover this case, but I'm not convinced it
would be worth it.

I'm not convinced either, but this seems like a good forum to discuss it. :)

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top