Sujet : Re: Whaddaya think?
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 19. Jun 2024, 21:13:19
Autres entêtes
Organisation : None to speak of
Message-ID : <87cyocy9ls.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
David Brown <
david.brown@hesbynett.no> writes:
On 19/06/2024 04:07, Keith Thompson wrote:
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
[...]
That's fine. A return statement or exit() call is unnecessary
in main() due to a special-case rule that was added in 1999 for
compatibility with C++. I don't particularly like that rule myself.
I choose to omit the return statement in small programs, but if
you want to add the "return 0;", I have absolutely no objection.
(I used to do that myself.) It even makes your code more portable
to old compilers that support C90. (tcc claims to support C99,
but it has a bug in this area.)
A minor point: The latest unreleased version of tcc appears to fix
this bug. In tcc 0.9.27, falling off the end of main (defined as
"int main(void)") returns some random status. In the latest version,
it returns 0, based on a quick experiment and a cursory examination
of the generated object code. (tcc doesn't have an option to
generate an assembly listing; I used "tcc -c" followed by "objdump
-d".)
>
Godbolt has support for tcc, which might be convenient if you want to
look at its output.
>
<https://godbolt.org/z/5hK7PbGbj>
If anyone cares, I found the git commit where this was fixed:
commit 3b9c3fd1860ceaa5684d5837455084707a7848c9
Author: Michael Matz <
matz@suse.de>
Date: 2018-11-03 22:17:20 +0100
Fix noreturn in main()
ISO C requires 'main' falling through the end without explicit
returns to implicitely return 0 (if declared as returning int).
The most recent release of tcc is 0.9.27, released 2017-12-17.
But the git repo (<git://repo.or.cz/tinycc.git>, mirror at
<
https://github.com/TinyCC/tinycc> has updates as recently as
2024-03-22. Post-0.9.27 updates are on the "mob" branch.
Godbolt's "TCC (trunk)" is built from the latest version in git.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */