Author: Didier Kryn Date: To: dng Subject: Re: [DNG] Ada
Le 05/04/2026 à 23:20, Steve Litt a écrit : > Didier Kryn said on Sun, 5 Apr 2026 10:44:26 +0200
>
>
>> an assignment hasn't a value -- I think a flag for C compilers
>> to forbid this would catch many bugs
> I don't understand what you mean in the preceding sentence.
In C, the instruction "n=0;" has a value (it is a valid
expression), which means that "k=n=0;" is a possible shortcut.
Essentially, this is, for the primitive C compiler, a way to save a
store and a fetch, because the value assigned to n is still in the
accumulator.
But this leads to dangerous constructs like "if(n=0)" being valid.
If an assignment was not an expression, this major source of errors
would disapear magically. But you would need to write "n=0; k=0" instead
of "k=n=0;"