|
|
Subscribe / Log in / New account

C23 reference links

C23 reference links

Posted Jul 24, 2024 12:05 UTC (Wed) by excors (subscriber, #95769)
In reply to: C23 reference links by Karellen
Parent article: GNU C Library 2.40 released

It used to be unspecified behaviour (meaning the standard "provides two or more possibilities and imposes no further requirements on which is chosen in any instance"), and I think the basic problem was that the standard was so vague as to be practically useless. With C11, portable code doesn't know whether realloc(ptr, 0)==NULL means success (ptr freed) or failure (ptr not freed), so the only way to write a correct program is to never call it with size=0.

C17 tightened the definition, but badly - the wording was internally inconsistent, and also incompatible with glibc, probably unintentionally. (https://sourceware.org/legacy-ml/libc-alpha/2019-08/msg00...)

(C17 also said "Invoking realloc with a size argument equal to zero is an obsolescent feature", which means it "may be considered for withdrawal in future revisions of this International Standard", so there's been plenty of warning.)

My guess is that the standards people realised it was really hard to come up with a precise definition that was self-consistent, useful, and compatible with reality, and it's not a good use of their time to keep discussing it when it's such a pointless feature anyway (just call free(ptr) if that's what you want), so they gave up and called it undefined. Platforms and compilers can still document the behaviour they actually implement, so nothing will really change.


to post comments

C23 reference links

Posted Jul 24, 2024 15:53 UTC (Wed) by khim (subscriber, #9252) [Link]

> It used to be unspecified behaviour (meaning the standard "provides two or more possibilities and imposes no further requirements on which is chosen in any instance"), and I think the basic problem was that the standard was so vague as to be practically useless.

Seriously? I have a newsflash for you: any practical programmer would attest that even extra-vague “anything but UB” definition is still better than UB.

Because “anything but UB” behavior should be predictable and debuggable. It may not be what you want or need, but it's not “your program works for years, then stops working because starts aligned differently” that UB signifies!


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds