Yet another slap on the hand by implicit bool to int conversions

Peter Alexander peter.alexander.au at gmail.com
Sun Jun 19 15:02:41 PDT 2011


On 19/06/11 10:51 PM, Timon Gehr wrote:
> Andrej Mitrovic wrote:
>> So I've had a pretty fun bug today when porting some code over to D.
>> When I port C code to D, first I do a one-to-one translation and make
>> sure everything works before I try to make use of any D features.
>>
>> Here's a function snippet, try to figure out what's wrong with the
>> code (don't worry about type definitions or external variables yet):
>>
>> http://codepad.org/gYNxJ8a5
>>
>> Ok that's quite a bit of code. Let's cut to the chase:
>>
>> if (mmioRead(hmmio, cast(LPSTR)&drum, DRUM.sizeof != DRUM.sizeof))
>> {
>>      mmioClose(hmmio, 0);
>>      return szErrorCannotRead;
>> }
>> [snip.]
>
> Maybe DMD could warn on nonsense of the form x != x.
>
>
> Timon

That would help in this particular case, but not in general.


More information about the Digitalmars-d mailing list