Featured post
c++ - Getting a past-the-end pointer -
possible duplicate:
take address of one-past-the-end array element via subscript: legal c++ standard or not?
const int n = ...; t a[n]; t* begin = &a[0]; //or t* end = begin + n;
i know legal , fine. wondering if following undefined behavior or legal well. answer depend on type t?
t* end = &a[n];
p.s. question curiosity question, please refrain mentioning vector better alternative arrays , :)
yes. undefined behavior. no, type of t doesn't matter.
the accepted answer in linked duplicate in error own selection of standard citations. unfortunately muddles logic @ end come opposite conclusion. note in 3.9.2/3 contained within paragraph quite talking type, not ability dereference. type of pointer (array+size) same "as-if" there valid object of type t there; not mean there valid object there , in fact there isn't.
there citation in duplicate of c99 standard states &array[index] not result in pointer dereference implied array[index]. c99 not c++ though , i've not seen equivalent text says same thing. rule legal in c.
c++0x contain of c99, don't know if bit included. should not consider them same language.
most c++ compilers happily eat run compliant compiler not.
- Get link
- X
- Other Apps
Comments
Post a Comment