Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Yea you have undefined behavior by I.o.b. Advice: in C the compiler usually isn't wrong.
-
grep347y@LicensedCrime its just pointer arithmetics, the intent of &a[1][3] is to point to the address past the last element of the array, like std::vector end() method.
The issue here is that dist1 is different at runtime than dist2 as seen in the console at the bottom right. This bug appears only with the constexpr stuff, no problem without that. (Also the debugger shows the right value dist1 = 6, not 3) -
It's not weird it's undefined. That is it may or may not work depending on external conditions. In this case it's undefined to take a pointer to an element past the end of the array, doesn't matter if it is 'just pointer maths'
-
grep347y@stevemk14ebr I disagree, please read http://wiki.c2.com//.... That part:
"According to the C and C++ standards, pointer arithmetic is only valid within an array or just off the end of it - it is valid to point to "one past the end" of the array provided that such pointers are never dereferenced."
Again this is used in the STL for std::vector::end(). Maybe you are working for Microsoft ? ;-)
Related Rants
With the brand new Microsoft C++ compiler, what you see in the debugger, is not always what you get...
undefined
c++
microsoft