2

Following recommendation from a stack user and instructions within the following stack question:

Lex - How to run / compile a lex program on commandline

I receive the following error after executing lex wordcount.l and gcc lex.yy.c -ll on OS X and my console window:

wordcount.l:16:1: warning: type specifier missing, defaults to 'int'
      [-Wimplicit-int]
main(argc, argv)

Is anyone able to help me resolve this error along with further explanation?

Specifically how would I specify the file such that it is found. Thank you.

aitía
  • 217
  • 2
  • 8
  • 1
    Lex is a very old program, so it outputs C language based on pre-ANSI standards. In particular, it doesn't declare main to return int, because early C compilers assume all functions return int unless told otherwise. Nowadays, that's seen as bad practice, hence the warning. But it will compile and run fine anyway. – Lee Daniel Crocker Jan 19 '18 at 01:15
  • 2
    @lee: lex doesn't declare main at all. That's the user's responsibility. (Using the main in libl doesn't involve a declaration.) Also, modern flex versions generate warning-free C code compilable with C99 or C11 (or even C++). – rici Jan 19 '18 at 02:53
  • 2
    Look at lines 16-18 of your code. Change it to `int main(int argc, char **argv)`. If there are mentions of `argc` or `argv` before the opening brace `{` of the body of `main()`, remove them. But if you’re going to do much programming with Lex, you need to brush up on your C to a point where you don’t need to ask this question. – Jonathan Leffler Jan 19 '18 at 03:02

0 Answers0