Closed winspool closed 1 year ago
They are equivalent in C23 (although not equivalent in C17 or earlier revisions).
I do not agree, @frederick-vs-ja
For main() in a hosted environment, two possible definitions are listed in the standard (since ages).
Some example code is using
int main()
but this variant is not listed in 5.1.2.2.1
in addition, the standard is also a guide, what to do and what not to do, and examples in the standard should follow the own rules.
Even for C17 and older standards, the standard has the same possible definitions for main (in a hosted environment)
@ThePhD Still present in n3088.pdf (First found Example: 6.7.2.2 Section 17 on Page 108)
Did you that N2432 and N2832.
no
5.1.2.2.1 imposes some lexicographical requirements on the form
int main(void) { /* ... */ }
?
Yes, i always mentioned 5.1.2.2.1, always related to hosted compiler. (in freestanding environments, everything can be different)
Yes, i always mentioned 5.1.2.2.1, always related to hosted compiler. (in freestanding environments, everything can be different)
What I meant was not about hosted and freestanding implementations. I meant that the requirements don't seem lexicographical.
There's a note explaining "or equivalent":
Thus,
int
can be replaced by a typedef name defined asint
, or the type ofargv
can be written aschar ** argv
, and so on.
So one is not required to write lexicographically exact int main(void) { /* ... */ }
in order to fit into the first form. With the changes in N2432 and N2841 (both adopted for C23), an empty parameter list is equivalent to that consists of a single void
.
I should change all the examples to use the same form, but honestly as its written is both pedantically correct and entirely equivalent (we made void f ();
equivalent to void f(void);
in C23).
The standard has example code with
When the arguments are not used in an example code, then please use the standard conforming version instead (see 5.1.2.2.1):