Path: csiph.com!news.mixmin.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: New features added into C23 standard Date: Mon, 15 Aug 2022 23:17:34 -0700 Organization: A noiseless patient Spider Lines: 25 Message-ID: <86y1vou2yp.fsf@linuxsc.com> References: <3093c98e-d014-47e4-bcf3-3f108d7c2c03n@googlegroups.com> <87mtcwzwt9.fsf@nosuchdomain.example.com> <88293f89-5f19-4fb3-844b-20e3a063b65cn@googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader01.eternal-september.org; posting-host="327aa8f3763fd82bcbb1f30d2282ba71"; logging-data="4639"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Qhn/F0QaIGALXQ1NpiJ9koOCAU1KS4sE=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:ZTMi15t/S2Mb1d03zgMf9lxoTmQ= sha1:B4YdZVieM2qu+0fC6xOYxikMvGc= Xref: csiph.com comp.lang.c:167036 Richard Damon writes: > On 7/31/22 5:12 AM, David Brown wrote: > >> It is also not uncommon in microcontrollers for address zero to be a >> useful address - and then it is user code that needs access. But it >> is rarely an issue in practice. The most common situation is having >> it as part of the flash for code, and it is typically part of the >> interrupt vectors or reset vector. You would only want to read it >> for something like a CRC check of the flash, and if you are >> concerned about the compiler handling a pointer to address zero in >> an unhelpful manner, you can use a pointer-to-volatile. The other >> cases I have seen are having memory mapped peripherals there - and >> again, you always use volatile accesses. > > And for machine specific case like this, the fact that derefencing a > NULL pointer is "just" Undefined Behavior, that can be Implementaton > Defined to do what is wanted, as opposed to some how PROHIBITED. Dereferencing a null pointer is unequivocally undefined behavior. It is never implementation-defined behavior. Even if an implementation defines and documents an extension that specifies a behavior for dereferencing a null pointer, as the C standard defines the terms such cases fall under the heading of undefined behavior, and not implementation-defined behavior.