Timeline for Why would accessing uninitialized memory necessarily be undefined behavior?
Current License: CC BY-SA 4.0
6 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 7, 2023 at 21:22 | comment | added | supercat | A more interesting address on the Apple II would be 0xC0EF. Reading that address within about a second of a disk access via controller in slot 6 will likely overwrite a track of data on the last accessed drive. | |
Sep 6, 2023 at 23:00 | comment | added | Pseudonym | Just as a comment on this, the C committee (and, indeed, K&R themselves) did think of memory-mapped I/O. That is what "volatile" is for. | |
Sep 6, 2023 at 22:13 | comment | added | Chris Dodd | The undefined behavior only applies when reading "an object of automatic storage duration that could have been declared with the register storage class (never had its address taken), and that object is uninitialized" (C11 spec 6.3.2.1.2) -- a local var -- so would not apply to global things like memory-mapped I/O (which would necessarily be implementation-dependent) | |
Sep 6, 2023 at 22:10 | comment | added | occipita | True. It's been a while since I read the C standard (and there have been a number of updates to it since then), but IIRC it does not distinguish between these categories, This may be an intentional simplification in order to keep the standard manageable. | |
Sep 6, 2023 at 22:06 | comment | added | kaya3 | This is a good point, but it applies to reading from arbitrary memory addresses ─ as opposed to known addresses of memory which isn't initialised yet, like uninitialised local variables. Presumably a local variable would not be stored in one of these special addresses which has side-effects when read. | |
Sep 6, 2023 at 22:02 | history | answered | occipita | CC BY-SA 4.0 |