Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #147486

Re: Why does 'gcc -Wall' complain about void main() ?

From Manfred <noname@add.invalid>
Newsgroups comp.lang.c
Subject Re: Why does 'gcc -Wall' complain about void main() ?
Date 2019-11-01 21:00 +0100
Organization Aioe.org NNTP Server
Message-ID <qpi2sl$1qeu$1@gioia.aioe.org> (permalink)
References <5fXuF.717$gt2.335@fx02.iad> <qphgf3$gqr$2@dont-email.me> <qpho6i$9bj$1@gioia.aioe.org> <lnftj77bc3.fsf@kst-u.example.com>

Show all headers | View raw


On 11/1/2019 6:31 PM, Keith Thompson wrote:
> Manfred <noname@add.invalid> writes:
>> On 11/1/2019 3:45 PM, David Brown wrote:
>>> On 01/11/2019 15:22, DFS wrote:
>>>> gcc 9.1.0 on MSYS2
>>>>
>>>> combinearrays.c:14:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
>>>>      14 | void main() {
>>>>         |      ^~~~
>>>>
>>>
>>> That is because the main should be declared as either:
>>>
>>> 	int main(void);
>>>
>>> 	int main(int argc, char *argv[]);
>>>
>>> or an implementation-specific extension (*nix systems often allow a
>>> third "envp" pointer).
>>
>> And version 0.01 of the linux kernel had:
>>
>> void main(void)      /* This really IS void, no error here. */
>> {                    /* The startup routine assumes (well, ...) this */
> 
> The kernel is considered to be in a freestanding environment, in
> which the program's entry point is entirely implementation-defined.
> For hosted environments, main returns int (or possibly some
> implementation-defined type, but that's rarely if ever useful).
> 

Indeed, and in fact main() has been renamed into some other init 
function as entry point of the kernel since long by now (I think it's 
start_kernel, although the source is still called main.c).
But I found the comment by Linus kind of interesting (possibly a warning 
for the unwary..)

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Why does 'gcc -Wall' complain about void main() ? DFS <nospam@dfs.com> - 2019-11-01 10:22 -0400
  Re: Why does 'gcc -Wall' complain about void main() ? David Brown <david.brown@hesbynett.no> - 2019-11-01 15:45 +0100
    Re: Why does 'gcc -Wall' complain about void main() ? Manfred <noname@add.invalid> - 2019-11-01 17:57 +0100
      Re: Why does 'gcc -Wall' complain about void main() ? Keith Thompson <kst-u@mib.org> - 2019-11-01 10:31 -0700
        Re: Why does 'gcc -Wall' complain about void main() ? Manfred <noname@add.invalid> - 2019-11-01 21:00 +0100
      Re: Why does 'gcc -Wall' complain about void main() ? David Brown <david.brown@hesbynett.no> - 2019-11-01 21:20 +0100
  Re: Why does 'gcc -Wall' complain about void main() ? Keith Thompson <kst-u@mib.org> - 2019-11-01 10:25 -0700

csiph-web