Article View: gnu.gcc.help
Article #937Re: gcc 2.7.2 warning: left-hand operand of comma expression has no effect
From: Glenn Carr
Date: Mon, 11 Mar 1996 15:53
Date: Mon, 11 Mar 1996 15:53
28 lines
1729 bytes
1729 bytes
Bill McCarthy wrote: > > In <313DEA09.237C@tulsa.lgc.com>, > Glenn Carr <gcarr@tulsa.lgc.com> writes: > > >We've just moved from gcc 2.6.3 to 2.7.2 and we're receiving the following new > >warnings (when -Wall is specified).... > > > >warning: left-hand operand of comma expression has no effect > > > >When this section of code is encountered in our source files... > > > >static char *rcsid = "$Id: cfgopen.c,v 1.4 1995/12/11 16:04:35 gcarr Exp $"; > >#if __GNUC__ == 2 > >#define USE(var) static void * use_##var = (&use_##var, (void *) &var) > >USE(rcsid); > >#endif > > Isn't comma in the #define is a comma operator? Then you are taking the > address of use_rcsid and discarding it. What will be returned to use_rcsid > is the address of rcsid (a char **) cast to a (void *). Yes, it is. It's a trick to inhibit the gcc warning about an unused variable for 'rcsid'. The initialization of use_rcsid 'uses' both rcsid and use_rcsid. I fixed the problem by casting the first operand of the comma operator to void... #define USE(var) static void * use_##var = ((void)&use_##var, (void *) &var)
Technical Details
Message-ID:
<31444C7F.794B@tulsa.lgc.com>Path:
arc1-ca.pugleaf.net!dildog.lgc.com!usenetReferences:
<313DEA09.237C@tulsa.lgc.com> <4hoan9$eav@castle.nando.net>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!dildog.lgc.com!usenet From: Glenn Carr <gcarr@tulsa.lgc.com> Newsgroups: gnu.gcc.help,comp.lang.c Subject: Re: gcc 2.7.2 warning: left-hand operand of comma expression has no effect Date: Mon, 11 Mar 1996 09:53:35 -0600 Organization: Landmark Graphics Message-ID: <31444C7F.794B@tulsa.lgc.com> References: <313DEA09.237C@tulsa.lgc.com> <4hoan9$eav@castle.nando.net> NNTP-Posting-Host: 134.132.131.47 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 2.0 (X11; I; AIX 1) To: Bill McCarthy <actuary@nando.net>