Fixing C's Biggest Mistake

Walter Bright newshound2 at digitalmars.com
Mon Jan 2 22:54:41 UTC 2023


On 1/1/2023 11:14 AM, kdevel wrote:
> On Sunday, 1 January 2023 at 18:11:10 UTC, Walter Bright wrote:
>> (C++ has the same issue.)
> 
> How? Quote from https://eel.is/c++draft/dcl.ref:
> 
>     [...] A reference shall be initialized to refer to a valid object or function.
> 
>     [Note 2: In particular, a null reference cannot exist in a well-defined
>     program, because the only way to create such a reference would be to bind it
>     to the “object” obtained by indirection through a null pointer, which causes
>     undefined behavior. {...} — end note]

The spec says don't do it. That doesn't stop it from happening, though, as the 
compiler has no way to detect it.



More information about the Digitalmars-d mailing list