[comp.std.c] are arrays allowed in strictly conforming programs?

eck@cs.vu.nl (Hans van Eck) (10/12/90)

In the December '88 draft of the standard in section 4.11.1, there is a line
that says:

If an array is accessed beyond the end of *an* object, the behavior is
undefined. (emphasis mine)

Isn't this unambiguously saying that strictly conforming programs are hardly
allowed to access arrays at all?

An example:
	int a[2];
	a[1] = 1;

This would be illegal since a[1] lies beyond a[0], which is an object.

Just curious.
--
Hans van Eck, Dept. of Mathematics and Computer Science, Vrije Universiteit,
De Boelelaan 1081, 1081 HV Amsterdam, The Netherlands
Voice: +31 20 5485302 			Email:	eck@cs.vu.nl

gwyn@smoke.BRL.MIL (Doug Gwyn) (10/12/90)

In article <7913@star.cs.vu.nl> eck@cs.vu.nl (Hans van Eck) writes:
>If an array is accessed beyond the end of *an* object, the behavior is
>undefined. (emphasis mine)

No, of course not.  The sentence (in the blanket rules for the <string.h>
function conventions) has no force outside 4.11 in any case, but more
specifically it is part of a larger context that you have dropped.  The
larger context is that some of the 4.11 functions could be requested to
operate on nonexistent objects, for example
	int src[3], dst[10];
	memcpy(dst, src, 10);
Instead of posting a warning in each function's subsection, the
injunction against attempting such abuse is posted in the blanket section.

eck@cs.vu.nl (Hans van Eck) (10/15/90)

gwyn@smoke.BRL.MIL (Doug Gwyn) writes:

>In article <7913@star.cs.vu.nl> eck@cs.vu.nl (Hans van Eck) writes:
>>If an array is accessed beyond the end of *an* object, the behavior is
>>undefined. (emphasis mine)

>The
>larger context is that some of the 4.11 functions could be requested to
>operate on nonexistent objects, for example
>	int src[3], dst[10];
>	memcpy(dst, src, 10);
>Instead of posting a warning in each function's subsection, the
>injunction against attempting such abuse is posted in the blanket section.

I am not completely convinced.  The point was that the standard talks about
*an* object.  It doesn't say that the object meant is the last element of
the array.

Hans
--
Hans van Eck, Dept. of Mathematics and Computer Science, Vrije Universiteit,
De Boelelaan 1081, 1081 HV Amsterdam, The Netherlands
Voice: +31 20 5485302 			Email:	eck@cs.vu.nl