Re: where exactly c++,c fail and Ada gets thru'



Simon Wright <simon@xxxxxxxxxxxx> writes:
"jimmaureenrogers@xxxxxxxxxxxxxxxx"
<jimmaureenrogers@xxxxxxxxxxxxxxxx> writes:

The C standard explicitly
allows one to access one element beyond the end of an array to
support common practice in thousands of C programs. The C
standard indicates that accessing more than one beyond the end
of an array leads to undefined behavior.

As I remember it, you are allowed to use the address of the element
one past the end of the array in a comparison with the addresses of
other elements of the same array, but not to access its content?

Correct. Note that "allowed to" is a fairly weak statement in C;
accessing elements beyond the bounds of an array isn't "allowed", but
it's undefined behavior, meaning that the implementation is under no
obligation to diagnose the error.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.



Relevant Pages

  • Re: SSCANF
    ... This gives undefined behavior. ... You're trying to modify ... in this context will evalutate to pointers to their ... array of three char). ...
    (comp.lang.c)
  • Re: The value of variables
    ... I write a programe as follows,and compile successfuly. ... end of an array invokes undefined behavior after which *anything* is ... including the nul character. ...
    (comp.lang.c)
  • Re: 3 questions about arrays
    ... If yes then it's undefined behavior. ... it only has to provide bigger fixnums. ... handle even if it means that part of the array would be in swap memory. ... each AREF would imply a bignum multiplication, ...
    (comp.lang.lisp)
  • Re: register
    ... >> 6.3.2.1 says that the implicit conversion of an array expression to a ... >> pointer to its first element invokes undefined behavior if the ... >> designated array object has register storage class. ... gcc complains "error: address of register variable 'a' requested" on ...
    (comp.lang.c)
  • Re: Compiler difference
    ... However, when I checked other examples of array and its size, they tend to ... Attempts to do so result in 'undefined behavior' ... Evalutating the value of this pointer will ... > String literals, by definition are not allowed to be ...
    (alt.comp.lang.learn.c-cpp)