DMD 0.148 release

Roberto Mariottini Roberto_member at pathlink.com
Mon Feb 27 01:59:36 PST 2006


In article <dtuatr$l0k$1 at digitaldaemon.com>, Ivan Senji says...
>
>Walter Bright wrote:
>> "Ivan Senji" <ivan.senji_REMOVE_ at _THIS__gmail.com> wrote in message 
>> news:dttebh$2kqq$1 at digitaldaemon.com...
>> 
>>>>Ever seen this:
>>>>
>>>>while(1)
>>>
>>>I sure did, and it scares the hell out of me :)
>> 
>> 
>> Why? This is a practice I got into with C/C++, and I did it because 1 cannot 
>> be redefined by the preprocessor into something goofy. I.e., I *knew* what 
>> it was without having to go spelunking through header files. 
>> 
>
>The reason should be obvious. While(condition). Condition should be 
>boolean (true or false). 1 is neither. It is an integer. Using 1 (or any 
>other int) in a conditions place just isn't type safe.

One of my students once had code written like this:

bool b1 = ... complex expression ... ;
..
bool b2 = ... complex expression ... ;
..
bool b3 = ... complex expression ... ;
..
if (b1 || (b2 && 3))
{
.. remove the file ...
}

(note the 'b' missing from 'b3').
Its program obviously removed the file at every run, no matter how it set the
three variables, even when the debugger said they were false all the three.
When I explained the student that 3 is always true, he asked to me: "Why? What
'3' has in common with 'true'?". I didn't know what to say.
Then the students complained at me that the compiler was buggy, since it didn't
signal that construct as an error. It took me one hour to explain this C/C++
design flaw/decision, but I think I didn't convince them all.

Ciao





More information about the Digitalmars-d-announce mailing list