18
grep
6y

With the brand new Microsoft C++ compiler, what you see in the debugger, is not always what you get...

Comments
  • 6
    Cool, didn't even know __LINE__ exists
  • 1
    Yea you have undefined behavior by I.o.b. Advice: in C the compiler usually isn't wrong.
  • 0
    @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)
  • 1
    @ComradeBob Yeah, I'm pretty impressed!
  • 1
    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'
  • 0
    @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 ? ;-)
  • 0
  • 0
    @runfrodorun get em!!!
Add Comment