This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: to bug or not to bug
- From: "Dave Hooper" <dave at beermex dot com>
- To: "al.neu" <al dot neu at softhome dot net>
- Cc: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 8 Jan 2003 16:22:47 -0000 (GMT)
- Subject: Re: to bug or not to bug
- References: <000001c2b727$3801ba00$bfef1ec4@albert>
> #define max(a,b) (a > b) ? a : b
> cChar = max(1,foo(faArray[iCount++]));
>
> /* INCORRECT output is obtained:
> output: > ii = 0 -> ii = 1 -> iCount=2 */
This is not a gcc bug. It is a bug in your definition of max. Think
about what the #define is doing. When the preprocessor expands max it
generates the following code:
cChar = (1 > foo(faArray[iCount++])) ? 1 : foo(faArray[iCount++];
You can see that foo gets called twice.
The 'bug' is in your definition of max. One solution would be to not use
a #define for this sort of thing. If you must, use an inline function.
d