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

Timon Gehr timon.gehr at gmx.ch
Sun Jun 19 14:51:58 PDT 2011


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


More information about the Digitalmars-d mailing list