Bug 27646 - compiling very simple flex generated code results in global variabl error with GCC 4.0.1
Summary: compiling very simple flex generated code results in global variabl error wit...
Status: RESOLVED DUPLICATE of bug 11751
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.0.1
: P3 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2006-05-17 19:02 UTC by jesse Rosenzweig
Modified: 2006-05-17 19:06 UTC (History)
50 users (show)

See Also:
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:


Note You need to log in before you can comment on or make changes to this bug.
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 ***