delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/09/09/18:46:54

From: AndrewJ <luminous-is AT REMOVE DOT home DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Warning : if (x=y)
Message-ID: <afelrschg9sb1dd01iktt3jnnivl6o86jn@4ax.com>
References: <8pd7q6$ljs$2 AT info DOT cyf-kr DOT edu DOT pl> <8pdc2s$1b6$2 AT news DOT luth DOT se>
X-Newsreader: Forte Agent 1.7/32.534
MIME-Version: 1.0
Lines: 42
Date: Sat, 09 Sep 2000 22:36:54 GMT
NNTP-Posting-Host: 24.42.120.18
X-Complaints-To: abuse AT home DOT net
X-Trace: news3.rdc1.on.home.com 968539014 24.42.120.18 (Sat, 09 Sep 2000 15:36:54 PDT)
NNTP-Posting-Date: Sat, 09 Sep 2000 15:36:54 PDT
Organization: Excite AT Home - The Leader in Broadband
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019