This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Warning about -Wmain for local variables


On 30 May 2018 at 11:40, Prathamesh Kulkarni wrote:
> gcc with -Wmain warns for local variables named main.
>
> int foo()
> {
>   int main = 0;
>   return main;
> }
>
> a.c: In function ‘foo’:
> a.c:3:7: warning: ‘main’ is usually a function [-Wmain]
>    int main = 1;
>        ^~~~
>
> Is this intended ? I assumed that the warning's intent was for
> diagnosing variable named main having only external linkage.

It was added more than 20 years ago by https://gcc.gnu.org/r13517 and
looks like it has always worked as it does now, without considering
linkage.

Only warning for entities with external linkage seems reasonable to
me, but that would be for the C front-end or diagnostics maintainers
to decide.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]