Mail Archives: djgpp/2000/09/09/18:46:54
On 9 Sep 2000 12:57:00 GMT, Martin Str|mberg <ams AT father DOT ludd DOT luth DOT se> wrote:
>: I have use Turbo Pascal for over 6 years, so now in C++ I'm often writing
Hahahahahahahaha.... sorry... Pascal... hahahahaha...
>: if (x=y)
>: instead of
>: if (x==y)
>
>: What is command-line option for turning on warning messages for this
>: expression ?
>
>"-Wall" does that. I'm not sure there is one particular for exactly
>that warning.
/* foo.c */
#include <stdio.h>
int main(void)
{
int a=12, b=16;
if(a=b)
printf("huh?\n");
printf("yoink!\n");
return(0);
}
'gcc -Wall -ansi -c foo.c' gives me:
FOO.C: In function `int main()':
FOO.C:6: warning: suggest parentheses around assignment used as truth value
Thar be a warning, me matey. The specific warning option is -Wparentheses,
check info gcc->warning options for more information.
To the OP, consider always using the -Wall and -ansi arguments for GCC. And
if you're really perverse, use -pedantic. You'll find it will pick up on a lot
of little things you may have missed, as well as forcing your code to be as
portable as is possible.
--
AndrewJ
- Raw text -