Bogus warning message about variables named 'main'

Tom Lane tgl@sss.pgh.pa.us
Sun Mar 21 10:59:00 GMT 1999


Hi folks,

Recent versions of egcs (at least since 2.91.63, probably longer)
generate a complaint about local variables named "main" if -Wmain or
-Wall is turned on.  This is coming from start_decl() in gcc/c-decl.c:

  if (warn_main && TREE_CODE (decl) != FUNCTION_DECL 
      && !strcmp (IDENTIFIER_POINTER (DECL_NAME (decl)), "main"))
    warning_with_decl (decl, "`%s' is usually a function");

I presume the real intent of this check is to catch *global* variables
named main, since they will cause link-time conflicts with main().
I can see no reason to complain about a function parameter or local
variable named main, and several good reasons not to.

In short: the above code is missing a clause to test whether the
declaration appears at global scope or not.

			regards, tom lane


More information about the Gcc-bugs mailing list