public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* GCC Bug in 3.3.2 and 3.3.3 ?
@ 2004-09-06  2:42 Dave Trollope, Diane Barrowman
  2004-09-06  2:47 ` Dave Trollope, Diane Barrowman
  0 siblings, 1 reply; 2+ messages in thread
From: Dave Trollope, Diane Barrowman @ 2004-09-06  2:42 UTC (permalink / raw)
  To: gcc

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: GCC Bug in 3.3.2 and 3.3.3 ?
  2004-09-06  2:42 GCC Bug in 3.3.2 and 3.3.3 ? Dave Trollope, Diane Barrowman
@ 2004-09-06  2:47 ` Dave Trollope, Diane Barrowman
  0 siblings, 0 replies; 2+ messages in thread
From: Dave Trollope, Diane Barrowman @ 2004-09-06  2:47 UTC (permalink / raw)
  To: gcc


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-09-06  2:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-06  2:42 GCC Bug in 3.3.2 and 3.3.3 ? Dave Trollope, Diane Barrowman
2004-09-06  2:47 ` Dave Trollope, Diane Barrowman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).