On 2021-04-18 13:01:05 +0300, Stefanos wrote:
> On Sun, 18 Apr 2021 06:35:22 +0200
> "Christian Jullien" <[email protected]> wrote:
> > So it does not make difference if main is defined with or without (void)
>
> Allow me to disagree here.
>
> A simple example taken from
> https://www.geeksforgeeks.org/difference-int-main-int-mainvoid/ shows the
> difference:
>
> /* Without void in main() */
>
> int printf(const char*, ...);
>
> int main()
> {
> static int i = 5;
> if (--i) {
> printf("%d ", i);
> main(10);
> }
> }
>
> $ gcc -Wall -Werror -std=c11 foo.c -o foo
> $ ./foo
> 4 3 2 1
This works with this ABI, but this doesn't prove that this will work
on every platform. As I've said, with main(), the compiler doesn't
check the prototype. So you won't get an error from the compiler due
to inconsistent definition / calls.
> ---------------------------------------------------------
>
> /* With void in main() */
>
> int printf(const char*, ...);
>
> int main(void)
> {
> static int i = 5;
> if (--i) {
> printf("%d ", i);
> main(10);
> }
> }
>
> $ gcc -Wall -Werror -std=c11 foo.c -o foo
> foo.c: In function ‘main’:
> foo.c:8:9: error: too many arguments to function ‘main’
> 8 | main(10);
> | ^~~~
> foo.c:3:5: note: declared here
> 3 | int main(void)
> | ^~~~
This time, the prototypes are checked, so that you get an error.
--
Vincent Lefèvre <[email protected]> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel