Re: [Flex-devel] #include <unistd.h> in middle of scanner: bad idea
flex is a tool for generating scanners
Brought to you by:
wlestes
From: Kang-Che S. <exp...@gm...> - 2020-08-07 04:26:22
|
On Thu, Aug 6, 2020 at 1:37 AM Kaz Kylheku <938...@ky...> wrote: > > Flex generates a file which contains > a #include <unistd.h> long after user material. This seems to be for > the sake of having a declaration of isatty. > > The problem with this is that the user code can #define macros that > can break the header. C programs have to be careful with what they > do before system headers are included. System headers can always be overridden by user code. A prominent example is feature test macros, which are defined before the inclusion of system headers and can change the ABI used for standard library functions. > Here is small repro test case: > > %{ > > #define pause blah[] > > %} > > %% > > Result: > > $ flex lex.l ; cc lex.yy.c > lex.l:3:15: error: declaration of ‘blah’ as array of functions > #define pause blah[] Why would anyone want to do that? Redefining a standard library symbol makes the code unportable (except for local scope redefines). > How about just an "extern int isatty(int)" somewhere? Forward declaration can somewhat defeat the purpose of the header. A library implementation might not declare the function exactly as described in the standard document. It might contain other attributes or ABI keywords. |