Reddit: SafeD - The Safe Subset of D

Don Clugston dac at nospam.com.au
Tue Mar 25 08:38:44 PDT 2008


Bruno Medeiros wrote:
> Charles D Hixson wrote:
>>
>> PPS:  When talking about casts or type conversions, please make it 
>> explicit whether the same bit pattern is maintained. I often read 
>> those descriptions, and realize that I can't figure out exactly what 
>> is happening.  With C I was always certain that I was just telling the 
>> compiler to think about the same piece of memory differently, and that 
>> nothing actually changed.  With more modern languages, a lot more 
>> magic happens under the hood, and I'm no longer as certain what's 
>> going on.  I often wonder after reading the documentation whether the 
>> same bit pattern is maintained, or whether an equivalent value is 
>> produced.  E.g., I've never tried casting a float to a long.  What 
>> would it produce?  I can't predict.  I'd often prefer to deal with 
>> ulongs or ucents rather than byte arrays, but then at other times I 
>> need to address particular bytes out of that value.  Because I don't 
>> really understand a cast, I just use byte arrays (well, ubyte).  But 
>> it's "sloppier".  Generally I'm dealing with a unitary entity, and 
>> needing to think of it as an array all the time is uncomfortable.  
>> (I'd even like a notation for dealing with particular bits, though I 
>> haven't needed that recently.)
>> Note that this isn't a request for a change in how things act, but 
>> rather in how they are documented.
>> I *suspect* that cast is presumed to be defined by C, and that it 
>> means "Think about they type differently, but don't change it's bit 
>> pattern", but I'm never quite certain.
> 
> Yup, this is one of the C legacy behaviors/mentality that I've found 
> ever more irritant. I would prefer that the language syntax would better 
> distinguish between opaque casts (no bit changes) and conversion casts 
> (bit changes, since a conversion is made).

I'm with you. The worst example: Despite the name, C++'s reinterpret_cast<> 
sometimes does _conversion casts_, involving bit changes.


More information about the Digitalmars-d-announce mailing list