Fixing C's Biggest Mistake
kdevel
kdevel at vogtner.de
Tue Jan 3 05:26:24 UTC 2023
On Monday, 2 January 2023 at 22:54:41 UTC, Walter Bright wrote:
> 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.
The C++ standard does not primarily say "don't do this or that"
but "if you do this or that your code does not form a valid
program".
> That doesn't stop it from happening,
By definition it does not happen in valid C++ programs. Urge
programmers to write valid C++ programs and all's right with the
world!
> though, as the compiler has no way to detect it.
It's like speeding. The guys who deploy road signs are not in
charge of surveilling the traffic.
More information about the Digitalmars-d
mailing list