Hi, 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, a.out Then press the a key and enter.
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 ***