[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] Clarification about log message in commit 48df89e10e
From: |
Christian Jullien |
Subject: |
Re: [Tinycc-devel] Clarification about log message in commit 48df89e10e |
Date: |
Sun, 18 Apr 2021 06:35:22 +0200 |
As Vincent said,
main is a special function known by the C compiler which requires no
declaration.
It accepts two different definitions (with implicit declaration):
- one without arg
- the other with int and char*[]
C verifies that definition matches the declaration. Correctly defined with void
(the prototype), a *definition* is perfectly legal without argument:
int foo(void);
int foo() {
return 42;
}
gcc -std=c11 -Wall -c foo.c
The same is true with g++
g++ -std=c++17 -Wall -c foo.cpp
So it does not make difference if main is defined with or without (void)
C.
-----Original Message-----
From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=orange.fr@nongnu.org] On
Behalf Of Vincent Lefevre
Sent: Saturday, April 17, 2021 20:05
To: tinycc-devel@nongnu.org
Subject: Re: [Tinycc-devel] Clarification about log message in commit 48df89e10e
On 2021-04-17 19:12:38 +0300, Stefanos wrote:
> The reason I asked this question is because I was reading the C standard and
> found the following parts at 5.1.2.2.1 [1] and at 6.7.5.3/14 [2]:
[...]
> An identifier list declares only the identifiers of the
> parameters of the function. An empty list in a function
> declarator that is part of a definition of that function
> specifies that the function has no parameters. The empty list in
> a function declarator that is not part of a definition of that
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> function specifies that no information about the number or types
> of the parameters is supplied.
>
>
> In other words, all the tests that use `int main()` are open to accept
> any number of parameters, correct?
"int main ()" defines no prototype, meaning that the compiler cannot
check whether the code is correct or not. This is old K&R C and should
no longer be used in general. AFAIK, for a function definition, if you
do not declare parameters in the K&R way, this is equivalent to void.
--
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)
_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel