DMD 0.148 release

Thomas Kuehne thomas-dloop at kuehne.cn
Tue Feb 28 14:47:54 PST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Walter Bright schrieb am 2006-02-27:
>
> "Thomas Kuehne" <thomas-dloop at kuehne.cn> wrote in message 
> news:0fo9d3-mb8.ln1 at birke.kuehne.cn...
>> # import std.stdio;
>> #
>> # int main(){
>> # int i = 3;
>> # bool a = true;
>
> The next line goes around the type system completely, invalidates any 
> invariants on the contents, and so any "surprising" results should be 
> unsurprising:
>
>> # bool b = *(cast(bool*)cast(void*) &i);

I was sure there was another way to subvert without casting though
can't find it right now.

related suggestion:

a) if( a == b ) { ... }
b) if( a != b ) { ... }

If, after constant folding, the lines above results in

a) if( a == true ) { ... }
b) if( a != true ) { ... }

then the the code

a) if( a != false ) { ... }
b) if( a == false ) { ... }

is generated.


consequences:
1) no changes in the D documentation are required

2) no runtime overhead

3) the code is a bit more robust against casting and bools returned
from external sources (e.g. C code)

Thomas



-----BEGIN PGP SIGNATURE-----

iD8DBQFEBOB93w+/yD4P9tIRAlJpAJ9IdclZxNNPVFIEl0N/jLrwlC1EAACeNnGi
4fXZOJBKlc/5ES50zb21khs=
=HMVz
-----END PGP SIGNATURE-----



More information about the Digitalmars-d-announce mailing list