Removing GCC warnings from flex- and bison- generated C code

Charlie Zender <zender@uci.edu>
9 Jan 2004 23:49:52 -0500

          From comp.compilers

Related articles
Removing GCC warnings from flex- and bison- generated C code zender@uci.edu (Charlie Zender) (2004-01-09)
Re: Removing GCC warnings from flex- and bison- generated C code eggert@twinsun.com (Paul Eggert) (2004-01-12)
Re: Removing GCC warnings from flex- and bison- generated C code haberg@matematik.su.se (2004-01-12)
Re: Removing GCC warnings from flex- and bison- generated C code fjh@cs.mu.oz.au (Fergus Henderson) (2004-01-12)
Re: Removing GCC warnings from flex- and bison- generated C johnmillaway@yahoo.com (John Millaway) (2004-01-16)
Re: Removing GCC warnings from flex- and bison- generated C code zender@uci.edu (Charlie Zender) (2004-01-16)
| List of all articles for this month |

From: Charlie Zender <zender@uci.edu>
Newsgroups: comp.compilers
Date: 9 Jan 2004 23:49:52 -0500
Organization: University of California at Irvine
Keywords: lex, yacc, question, comment
Posted-Date: 09 Jan 2004 23:49:52 EST

Hi,


[I hope this is on topic, if not where should I send it?]


I am trying to get a code to compile warning free with GCC so that I
may use the -Werror option to help find new bugs. The remaining
warnings in my code all appear to be generated when the lexer and
parser files are compiled. These files, ncap_lex.c, and ncap_yacc.c,
respectively, are generated from ncap_lex.l and ncap_yacc.y by flex
and by bison, respectively. The unwanted warning messages thus appear
to be connected to code that is "automatically" generated.


1. Are flex and bison intended to produce files that are warning free
        code when compiled with stringent compiler options?
        (I use most of the GCC compiler options recommended by GSL:
        -Wall -Wunused -W -Wmissing-prototypes -Wshadow -Wpointer-arith \
        -Wcast-qual -Wcast-align -Wwrite-strings -fshort-enums -fno-common)
2. If so, do other lexer/parsers generate these warnings (see below)
        of does this indicate a poorly written/incomplete .l and .y file
        on my part?
3. Any recommendations for portable ways of eliminating most of these
        warnings would be appreciated. It may be safely assumed that flex
        and bison will always be used to process the .l and .y files.


Thanks!
Charlie


if cc -std=c99 -pedantic -D_BSD_SOURCE -DHAVE_CONFIG_H -I. -I. -I../..
    -I/usr/local/include -g -O2 -Wall -Wunused -W -Wmissing-prototypes
-Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings
-fshort-enums -fno-common -g -O4 -MT ncap_yacc.o -MD -MP -MF
".deps/ncap_yacc.Tpo" \
      -c -o ncap_yacc.o `test -f 'ncap_yacc.c' || echo './'`ncap_yacc.c; \
then mv -f ".deps/ncap_yacc.Tpo" ".deps/ncap_yacc.Po"; \
else rm -f ".deps/ncap_yacc.Tpo"; exit 1; \
fi
ncap_yacc.c: In function `yyparse':
ncap_yacc.c:1216: warning: implicit declaration of function `yylex'


if cc -std=c99 -pedantic -D_BSD_SOURCE -DHAVE_CONFIG_H -I. -I. -I../..
    -I/usr/local/include -g -O2 -Wall -Wunused -W -Wmissing-prototypes
-Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings
-fshort-enums -fno-common -g -O4 -MT ncap_lex.o -MD -MP -MF
".deps/ncap_lex.Tpo" \
      -c -o ncap_lex.o `test -f 'ncap_lex.c' || echo './'`ncap_lex.c; \
then mv -f ".deps/ncap_lex.Tpo" ".deps/ncap_lex.Po"; \
else rm -f ".deps/ncap_lex.Tpo"; exit 1; \
fi
ncap_lex.c:1034: warning: no previous prototype for `yylex'
ncap_lex.l: In function `yylex':
ncap_lex.l:670: warning: implicit declaration of function `yy_flex_realloc'
ncap_lex.c: In function `yy_init_buffer':
ncap_lex.c:2595: warning: implicit declaration of function `fileno'
ncap_lex.c: At top level:
ncap_lex.c:2840: warning: no previous prototype for `yyget_lineno'
ncap_lex.c:2849: warning: no previous prototype for `yyget_in'
ncap_lex.c:2857: warning: no previous prototype for `yyget_out'
ncap_lex.c:2865: warning: no previous prototype for `yyget_leng'
ncap_lex.c:2874: warning: no previous prototype for `yyget_text'
ncap_lex.c:2883: warning: no previous prototype for `yyset_lineno'
ncap_lex.c:2895: warning: no previous prototype for `yyset_in'
ncap_lex.c:2900: warning: no previous prototype for `yyset_out'
ncap_lex.c:2905: warning: no previous prototype for `yyget_debug'
ncap_lex.c:2910: warning: no previous prototype for `yyset_debug'
ncap_lex.c:2916: warning: no previous prototype for `yylex_destroy'


Note: this is all source code from the NCO project http://nco.sf.net
I am happy to send the original code to anyone interested.


--
Charlie Zender, surname@uci.edu, (949) 824-2987, Department of Earth
System Science, University of California, Irvine CA 92697-3100
Visiting NCAR 12/13/03--1/17/04: ***********************************
Voice/FAX: (303) 497-1724/1348, Office: Mesa Lab 259b **************
[I don't usually get warnings like that. What versions of bison and
flex are you using? -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.