Getting action on your favorite D issues

Avrina avrina12309412342 at gmail.com
Sat Jun 6 18:30:15 UTC 2020


On Saturday, 6 June 2020 at 15:16:06 UTC, ag0aep6g wrote:
> On 06.06.20 16:34, Avrina wrote:
>> On Saturday, 6 June 2020 at 10:09:07 UTC, Patrick Schluter 
>> wrote:
> [...]
>>> Sorry, but undefined behaviour is undefined behaviour. The 
>>> dmd code generator is not at fault here.
>> 
>> With statements like this I always feel like people don't 
>> understand what "undefined behavior" means.
>
> I'm not so sure if you really understand what "undefined 
> behavior" means.
>
> By saying this:
>
>> All the void initializer does is not initialize the memory of 
>> the bool.
>
> you're defining the behavior of using void initialized values. 
> Once you do that, it's not undefined behavior anymore.

So your saying void initializers don't have a defined function 
then? So if LDC wants it could initialise the memory.of all void 
initialized variables to zero and that would be considered within 
defined behaviour? If void initializers are undefined behaviour 
then the feature is useless.

> But the spec doesn't do that. Instead it says: "If a void 
> initialized variable's value is used before it is set, the 
> behavior is undefined." That is, the spec explicitly says that 
> doing so is not allowed, and that compilers may assume that it 
> doesn't happen. Because that's what "undefined behavior" means.

The spec is poorly written. The language doesn't do what's 
written in it for a lot of cases on top of that.

It just means the compiler can choose to implement it in any way 
it wants. DMD chooses to treat a boolean as both a 1-bit integer 
and an 8-bit integer. That isn't consistent with its own 
implementation. There's no reason for it to to be consistent.

> But Walter agrees with you: Using a void value shouldn't 
> actually have undefined behavior; it should just be an 
> arbitrary value. Which is why he has an open pull request to 
> change the spec:
> https://github.com/dlang/dlang.org/pull/2260

Yea and that pull request is years old. If that change does go 
into effect then the spec will reflect the actual reality of what 
is happening.



More information about the Digitalmars-d mailing list