:: Re: [DNG] What is the meaning of th…
Página Inicial
Delete this message
Reply to this message
Autor: Jonathan Wilkes
Data:  
Para: Didier Kryn, dng@lists.dyne.org
Assunto: Re: [DNG] What is the meaning of this gcc warning?
Why wouldn't you just write this:    dir = opendir(IFACES_PATH);    if (dir) { etc.

It is simple and readable.
-Jonathan



     On Monday, October 19, 2015 12:07 PM, Didier Kryn <kryn@???> wrote:



Le 19/10/2015 16:09, Rainer Weikusat a écrit :
> Edward Bartolo <edbarx@???> writes:
>> Could someone explain to me what is the meaning of this error and what
>> I should do to avoid having this warning?
>>
>> edbarx@edbarx-pc:~/netman/backend_src/src$ gcc -Wall -Wfatal-errors -g
>> -lm -I../include core_functions.c file_functions.c backend.c
>> essid_encoder.c automated_scanner.c -o backend
>> automated_scanner.c: In function ‘autoWirelessScanPlus_RN’:
>> automated_scanner.c:521:2: warning: suggest parentheses around
>> assignment used as truth value [-Wparentheses]
>>    if ( dir = opendir(IFACES_PATH) ) {
>>    ^
> The warning really only communicates that - ca 42 years ago - some
> ... American (!!1) dared to do something Nikolaus Wirth strongly
> disapproved of, namely, make assignment an expression instead of a
> statement (something Mr Wirth already strongly(!!2) disapproved of the
> the context of Algo 68) and then didn't use the assignment operator Mr
> Wirth had approved of (!!3), namely, :=.
>
> I don't know if this is the oldest, entirely pointless "programming
> language syntax war" in existance but it's surely one of the most
> persistently annoying ones[*].
>
> [*] Sometimes, when noticing that everyone else is driving in the
>      opposite direction on a motorway, you're actually wrong yourself ...
>


    Writing  "if (a = b)" when meaning "if (a == b)" is a very easy
mistake. Yes it is dangerous, because difficult to notice and it changes
dramatically the behaviour of the program. Any C programmer pretending
to never have made this mistake is a liar. Gcc authors have aknowledged
the fact by introducing this parenthesis feature which is supposed to
mean "yes I do mean an assignment".

    You are right, C cumulates these two features:

    1) the assignment operator is '='
    2) the assignment is an expression.

    Sure both are motivated; but the motivations are mostly aesthetical
while the combination is an unextinguishable source of bugs. I don't
think you can accuse the authors of gcc to make the war against the C
language because they warn you against this possible mistake, or do you
mean this Mr Wirth you seem to disaprove is (one of) the authors of gcc?

    Didier

_______________________________________________
Dng mailing list
Dng@???
https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng