GCC Bug in 3.3.2 and 3.3.3 ?
Dave Trollope, Diane Barrowman
daveanddiane@kringlecottage.com
Mon Sep 6 02:47:00 GMT 2004
Never mind - Have to remember my operator precedence.... a simple ()
fixes it.
Dave
Dave Trollope, Diane Barrowman wrote:
> 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
More information about the Gcc
mailing list