User account creation filtered due to spam.

Bug 27646

Summary: compiling very simple flex generated code results in global variabl error with GCC 4.0.1
Product: gcc Reporter: jesse Rosenzweig <jesser>
Component: cAssignee: Not yet assigned to anyone <unassigned>
Severity: critical CC: alexey, algorithmus, asokumar, av1474, bala, barnarr, behloul.younes, bmead15, buergel, carpman, chuchunxin, devnull, d_picco, eric.mcvicker, fuchsia.groan, gaurav_har, gcc-bugs, gcc, ggs, jandres, janis, jesser, jompo, krs, lid, lindahlb, lxg8906, mayer, mikaldaz, mike.clarkson, nakkore, nobs,, qyang, ramiller, raoulgough, raphael.ribas, rglan, rjvbertin, robc, s9322036, SimonX200, smartmouse714, suan, super.aorta, svetozarmarkov, tczarnecki, vanveghel, vitaly, zshao
Priority: P3    
Version: 4.0.1   
Target Milestone: ---   
Host: MacBookPro OSX Target: MacBookPro OSX i686-apple-darwin8
Build: GCC version 4.0.1 build 5250 Known to work:
Known to fail: Last reconfirmed:

Description jesse Rosenzweig 2006-05-17 19:02:23 UTC

My system is a macbook pro (intel duo core) with standard install of OS X.  GCC version 4.01 Build 5250.

I am writing a flex program and ran across a very strange issue.  When building and running the following flex (lex) program, the global variable access does not work properly.  The expected output from this program (when the a character is found) is :

glo = 5
5 = ret, glo = 5

but when building/running this program using GCC 4.01 , I get this output:

glo = 5
5 = ret, glo = 0

It works well with GCC v3.x

Here is the simple lex program:

#include <stdio.h>

#define yywrap() 1

int glo;

"a"    { glo = 5;
         printf("glo = %d\n", glo);
         return (int)5;

main ()
    printf("%d = ret, glo = %d", yylex(), glo);

To build this, I am running:
flex test.l
gcc lex.yy.c

to run,

Then press the a key and enter.
Comment 1 Andrew Pinski 2006-05-17 19:06:04 UTC
printf("%d = ret, glo = %d", yylex(), glo);

The C standard does not specify if yylex() or glo is evulated first.
So you are running into that effect and this is code undefined.

See PR 11751 for future reference.

*** This bug has been marked as a duplicate of 11751 ***