Re:How to find size of an array in C without sizeof
by kbart on Tuesday December 27, 2016 @02:00AM
(#13261710)
Read "undefined behavior" as "depending on architecture and compiler". It's not like anything can happen, but it's simply not to describe every architecture and every compiler into a standard. Sure, somebody is free to write an implementation where a nuke is launched every time "undefined behavior" is encountered, and they would be right according to C standard, but in real world, you pretty much know what to expect on a given system.
[ Parent
| on HN ]
Re:How to find size of an array in C without sizeof
by DougBTX on Tuesday December 27, 2016 @02:22AM
(#13261773)
> "depending on architecture and compiler".
The standard also has the idea of "implementation defined" behaviour, which is close to the definition above. "Undefined behaviour" is a trickier beast, since compilers can rightly assume undefined behaviour never occurs, and optimise accordingly.
Re:How to find size of an array in C without sizeof
by noselasd on Tuesday December 27, 2016 @04:14AM
(#13262137)
Not at all - that would be implementation defined behavior.
These days, compilers quite often speculate on undefined behavior, generating code as if the undefined part cannot happen - the result is that your code is going to do stuff you pretty much can not know or expect.