[Solved] C error with Flex: type specifier missing?


Assembled from comments (because it was easier than finding a dupe):

  1. In modern C (that is, C from this century), all functions need a return type and the only two legal prototypes for main are:

    int main(void)
    
    int main(int argc, char* argv[])
    

    An obsolescent way to write the first is int main().

  2. On Max OS, the flex distro doesn’t include libfl.a. It comes with libl.a. So use -ll instead of -lfl. But much better is to avoid the problem by telling flex not to require yywrap by putting the following declaration in your prologue:

    %option noyywrap
    

    Even better is to use the following:

    %option noinput nounput noyywrap nodefault
    

    noinput and nounput will avoid “unused function” warnings when you compile with warnings enabled (which you should always do). nodefault tells flex to not insert a default action, and to produce a warning if one would be necessary. The default action is to echo the unmatched character on stdout, which is usually undesirable and often confusing.

7

solved C error with Flex: type specifier missing?