Undefined behavior in C is a reading error
yodaiken.com
Undefined behavior in C is a reading error
1–10 of 503 posts
Re: Undefined behavior in C is a reading error
#2Re: Undefined behavior in C is a reading error
#3Re: Undefined behavior in C is a reading error
#4Making a system call is undefined behavior in the C standard, but it's not undefined behavior in clang-on-FreeBSD, because the implementors of clang on FreeBSD have defined what those system calls do.
Ditto for "asm" (UD unless/until you're running on a compiler which defines what that does), all of the tricks which make "malloc" work, and all of his other examples of acceptable uses of code which the C standard does not define.
Re: Undefined behavior in C is a reading error
#5Re: Undefined behavior in C is a reading error
#6The author seems to be missing this essential text: "the implementor may augment the language by providing a definition of the officially undefined behavior." Making a system call is undefined behavior in the C standard, but it's not undefined behavior in clang-on-FreeBSD, because the implementors of clang on FreeBSD have defined what those system calls do. Ditto for "asm" (UD unless/until you're running on a compile…
The idea that UB is carte blanche for implementations to do whatever is an unintended consequence of the vague language of the standard. Maybe a future C standard should use "safe" and "unsafe" instead of UB for some of these operations, and clarify that unsafe code will be erroneous in a safe environment and do something sensible but potentially dangerous in an unsafe environment so you must really know what you're doing.
Re: Undefined behavior in C is a reading error
#7The author seems to be missing this essential text: "the implementor may augment the language by providing a definition of the officially undefined behavior." Making a system call is undefined behavior in the C standard, but it's not undefined behavior in clang-on-FreeBSD, because the implementors of clang on FreeBSD have defined what those system calls do. Ditto for "asm" (UD unless/until you're running on a compile…
Re: Undefined behavior in C is a reading error
#8Duplicate, https://news.ycombinator.com/item?id=27217981
Re: Undefined behavior in C is a reading error
#9If C is just a portable assembler then what if the assembly itself has undefined behaviour. :)
Though it HAS happened: notably, brucedawson explains here [1] that the 360 has an instruction so badly thought out that merely having it in an executable page is enough to make your program otherwise meaningless due to speculative execution.
[1] https://randomascii.wordpress.com/2018/01/07/finding-a-cpu-d...
Re: Undefined behavior in C is a reading error
#10If C is just a portable assembler then what if the assembly itself has undefined behaviour. :)
This exists, but the effect of undefined behavior in CPU architectures is a little bit more forgiving than the interpretation of UB in C to mean "literally the entire program has no meaning". Instead, usually the program will execute correctly up to the invalid instruction, and then something happens, and then the CPU will continue executing from that state. It's actually fairly difficult to build an instruction with…