News for hackers. Stuff that matters.
Re:Undefined behavior in C is a reading error by faho on Thursday May 20, 2021 @12:35PM (#27223402)
So if it is behavior that is not defined by the C standard, would that not make it undefined behavior?
Re:Undefined behavior in C is a reading error by steveklabnik on Thursday May 20, 2021 @01:01PM (#27223804)
There is a difference between jargon in context and the use of those words in a general sense. It can be "undefined behavior" in a general sense, but not necessarily "undefined behavior" in the jargon sense.

After all, if I were to use the words "undefined behavior" in a sentence unrelated to the standards, the definition in the standard of "behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which this International Standard imposes no requirements." would be nonsense. Same goes in the other direction.

Re:Undefined behavior in C is a reading error by colejohnson66 on Thursday May 20, 2021 @12:57PM (#27223764)
While technically correct, “undefined behavior” in terms of C and C++ refer to what the standard calls out explicitly as undefined, and not a simple “it’s not referenced, therefore it’s undefined.”

For example, signed(?) integer overflow is explicitly undefined by the standard, but as @formally_proven said, just because write(2) isn’t mentioned doesn’t mean usage of it is undefined.

Re:Undefined behavior in C is a reading error by _kst_ on Thursday May 20, 2021 @02:16PM (#27224974)
Actually, that's exactly what it means:

> If a "shall" or "shall not" requirement that appears outside of a constraint or runtime-constraint is violated, the behavior is undefined. Undefined behavior is otherwise indicated in this International Standard by the words "undefined behavior" or by the omission of any explicit definition of behavior. There is no difference in emphasis among these three; they all describe "behavior that is undefined".

write() is a function, and a call to it behaves like a function call, but the C standard says nothing about what that function does. You could have a function named "write" that writes 0xdeadbeef over the caller's stack frame. Of course if "write" is the function defined by POSIX, then POSIX defines how it behaves.

Re:Undefined behavior in C is a reading error by aw1621107 on Friday May 21, 2021 @06:04PM (#27240556)
> but the C standard says nothing about what that function does

I'm pretty sure I'm just bad at searching through the standards document, but does the Standard actually define the precise semantics of function calls? 6.2.2 is about the function calls and the result thereof, but doesn't seem to be quite as precise about the semantics as I might expect.