tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Clarification about log message in commit 48df89e10e


From: Vincent Lefevre
Subject: Re: [Tinycc-devel] Clarification about log message in commit 48df89e10e
Date: Sun, 18 Apr 2021 12:57:34 +0200
User-agent: Mutt/2.0.6+152 (36a704cf) vl-132933 (2021-04-17)

On 2021-04-18 13:01:05 +0300, Stefanos wrote:
> On Sun, 18 Apr 2021 06:35:22 +0200
> "Christian Jullien" <eligis@orange.fr> 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 <vincent@vinc17.net> - 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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]