I'm looking for a way to insert an #undef
to the lex generated source code that will appear before the built in lines lex generates.
When compiling a file.l with lex, I generate a lex.yy.c
file. In my file.l
I have written :
#include "y.tab.h"
#undef __STRICT_ANSI__
#include <string.h>
The #undef
helps me compile the code under the flag -std=c99
So it needs to be done before including string.h
. But the generated file includes string.h
before copying my undef.
Without the #undef
I am getting a lot of warnings due to the use of strdup
. I have seen the normal fixes using flags, but like I said I can't access the makefile.
Adding 'manually' the line
#undef __STRICT_ANSI__
into lex.yy.c before fixes everything. But i prefer not to touch any of the generated code and have it done by lex.
I have read this, strdup(): Confused about warnings ('implicit declaration', 'makes pointer...without a cast', memory leak) And like i said it does solve it. But only if I can somehow force the generated file to run the undef first.