Timeline for What are the conditions necessary for a programming language to have no undefined behavior?
Current License: CC BY-SA 4.0
10 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 20, 2023 at 1:01 | comment | added | Pseudonym♦ | @ruakh As Kevin noted, the current behaviour of certain compilers is that the existence of a construct for which UB is possible constitutes a proof that the UB never occurs. Without documentation explaining this, it is not one of the enumerated behaviours in the C89 standard. | |
Aug 19, 2023 at 22:52 | comment | added | ruakh | @KevinCathcart: Definitely! But I'm not convinced that this difference between old compilers and newer compilers really results from the slight change in wording between the C89 and C99 standards. | |
Aug 18, 2023 at 23:03 | comment | added | Kevin Cathcart | @Barmar While true, many people feel there's a difference between old compilers where UB would either do the obvious thing for the machine (even if not desirable), or be unhandled (which in combination with optimizations could have strange results) (which feels akin to the old definition), and a compiler deciding that if you shift a signed integer left by a variable x that constitutes a proof that x<sizeof(int)*CHAR_BIT, which it can use for later optimizations. I'm not sure if any compiler has implemented that scenario, but some have implemented similar inferences for other UB scenarios. | |
Aug 18, 2023 at 14:18 | comment | added | Barmar | I'm not sure there's really much difference between the two definitions of UB. The inclusion of "unpredictable results" in the first version makes any result possible, so there's little difference between "possible" and "permissible". The rewording was presumably made for clarity, not to impose any different requirements. | |
Aug 18, 2023 at 11:09 | comment | added | Pseudonym♦ | @HansOlsson Yes. I think that a lot of C programmers which predate C99 have (or, at least, had) a mental model that "undefined behaviour" means "implementation-defined behaviour". Compiler developers have changed that in recent decades; it now unofficially means "benchmark-exploitable behaviour". | |
Aug 18, 2023 at 11:07 | history | edited | Pseudonym♦ | CC BY-SA 4.0 |
edited body
|
Aug 18, 2023 at 11:05 | comment | added | Pseudonym♦ | @Bergi Yes, it was a similar, but distinct, question. | |
Aug 18, 2023 at 11:02 | comment | added | Hans Olsson | Note that languages can also have implementation-defined behavior. That allows the defined behavior to depend on the hardware, so that it is two's compliment on machines that have it and sign-bit for the others; reducing the overhead in point 3 - but making the language less portable. (Sort of making a language dialect for each implementation.) | |
Aug 18, 2023 at 10:10 | comment | added | Bergi | Ah, I thought I had read this answer already elsewhere… | |
Aug 18, 2023 at 5:45 | history | answered | Pseudonym♦ | CC BY-SA 4.0 |