ThePhD / future_cxx

Work done today for the glory of tomorrow - or, C and C++ systems programming papers.
https://thephd.dev/portfolio/standard
46 stars 8 forks source link

c23_draft (n3054): examples use main () #62

Closed winspool closed 1 year ago

winspool commented 1 year ago

The standard has example code with

int main ()

When the arguments are not used in an example code, then please use the standard conforming version instead (see 5.1.2.2.1):

int main (void)
frederick-vs-ja commented 1 year ago

They are equivalent in C23 (although not equivalent in C17 or earlier revisions).

winspool commented 1 year ago

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)

frederick-vs-ja commented 1 year ago

Did you mean that N2432 and N2841 are still insuffient to make int main() { /* ... */ } equivalent to int main(void) { /* ... */ }, or 5.1.2.2.1 imposes some lexicographical requirements on the form int main(void) { /* ... */ }?

winspool commented 1 year ago

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)

frederick-vs-ja commented 1 year ago

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 as int, or the type of argv can be written as char ** 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.

ThePhD commented 1 year ago

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).