[Joke] C++ and D namings

Steven Schveighoffer schveiguy at gmail.com
Wed Jan 20 05:04:44 UTC 2021


On 1/19/21 11:21 PM, Ola Fosheim Grostad wrote:
> On Wednesday, 20 January 2021 at 04:15:24 UTC, Steven Schveighoffer wrote:
>> Only if the real item is actually const. This is literally the first 
>> example on cppreference:
>>
>>     int i = 3;                 // i is not declared const
>>     const int& rci = i;
>>     const_cast<int&>(rci) = 4; // OK: modifies i
>>
> 
> How is this different from D? How does this lead to different code gen?
> 

This is undefined behavior in D. How does it lead to different code Gen? 
This code could pass in D, but the equivalent C++ would have to fail 
since it's not UB:

int i = 3;
const int *j = &i;
*(cast(int *)j) = 4;
assert(i == 3);

-Steve


More information about the Digitalmars-d mailing list