This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
GCC Bug in 3.3.2 and 3.3.3 ?
- From: "Dave Trollope, Diane Barrowman" <daveanddiane at kringlecottage dot com>
- To: gcc at gcc dot gnu dot org
- Date: Sun, 05 Sep 2004 21:42:41 -0500
- Subject: GCC Bug in 3.3.2 and 3.3.3 ?
Hi
I seem to have run across some strange behaviour with using a function
call in the conditional of "? :".
See the following simple code:
#include <stdio.h>
char *glob[3] = { "a", "b", "c" };
char *x_ptr(int a)
{
return glob[a];
}
int main()
{
#ifdef BUG
char *xx;
printf("DBG %s\n",xx = x_ptr(2) ? xx : "JUNK");
#else
char *xx = x_ptr(2);
printf("DBG %s\n",xx ? xx : "JUNK");
#endif
}
If you compile with the BUG define, xx is assigned a bad pointer and
either core dumps or prints garbage. If you compile without BUG defined,
everything is fine.
Is this a known problem?
Can someone test this on 3.4.x?
I have reproduced this on cygwin with gcc3.3.3 and Mandrake Linux 10
using gcc3.3.2 but don't have 3.4.x to hand.
Cheers
Dave
--
Dave, Diane & Kringle
http://www.geocities.com/SiliconValley/7499