delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/09/09/08:18:47

From: "Thomas Harte" <T DOT Harte AT btinternet DOT _c_o_m_>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Warning : if (x=y)
Date: Sat, 9 Sep 2000 13:05:25 +0100
Organization: BT Internet
Lines: 25
Message-ID: <8pd96i$3bv$1@neptunium.btinternet.com>
References: <8pd7q6$ljs$2 AT info DOT cyf-kr DOT edu DOT pl>
NNTP-Posting-Host: host62-7-124-28.btinternet.com
X-Newsreader: Microsoft Outlook Express 4.72.3155.0
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3155.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Rafał Maj wrote in message <8pd7q6$ljs$2 AT info DOT cyf-kr DOT edu DOT pl>...
>What is command-line option for turning on warning messages for this
>expression ?


I don't think there is one, since it is perfectly valid syntax. It assigns
the value of x to y, and then evaluates the if statement based on that
value - 'TRUE' if the value is non-zero. In actual fact these assignments
are terribly useful, for example :

char *a;

if (a = (char *)malloc(32)) //with (char *) cast for pedants / C++ users
{
 ...
}
else
  printf("Malloc failed");

If the malloc succeeds, 'a' correctly points to the 32 bytes of memory.

-Thomas


- Raw text -


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