Sujet : Re: Whaddaya think?
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 16. Jun 2024, 21:32:05
Autres entêtes
Organisation : None to speak of
Message-ID : <87tths39yy.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Janis Papanagnou <janis_papanagnou+
ng@hotmail.com> writes:
On 16.06.2024 07:49, Keith Thompson wrote:
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
>
void main (int argc, char * argv[])
*Ahem* -- int main.
>
Never sure about whether it was/is correct to 'void'-declare
the return value and/or the [unused] main() arguments. (I'm
still from the early C time when types were even omitted as
function return specification (presuming an implicit int or
no return), as in the K&R book. During the past decades I
tended to declare my intention by writing f(void) instead
of f() and void f() where no results are delivered. K&R at
least seems to say that 'void' can only be declared for the
return type of functions that do not return anything.
>
As long as my C compiler doesn't mind 'int main (void)' or
'void main (int, char **)' I don't care much for test code.
I'm sure this stance of mine might be considered offensive
in a 'C' NG. - Apologies! :-)
No version of C has ever permitted "void main" except when an
implementation documents and permits it. The 1989 ANSI C standard
both introduced the "void" keyword and specified the two permissible
definitions of main, both of which return int. Prior to C99,
defining main without an explicit return type was equivalent to
"int main". Many compilers will permit "void main", and might not
warn about it by default, but it has undefined behavior unless the
implementation documents it as an option. The calling environment will
assume that main returns an int value.
This applies to hosted implementations; in a freestanding
implementation, the program entry point is defined by the implementation
and might not even be called "main".
There is no advantage in writing "void main" rather than "int main".
Since C99, falling off the end of main does an implicit "return 0;".
"int main" is guaranteed to work; "void main" is not.
On my system, if I define "void main" the exit status seen by the shell
is some arbitrary value (I got 41 just now with gcc, 48 with clang, 165
with tcc).
See also questions 11.12a and following in the comp.lang.c FAQ,
<
https://www.c-faq.com/>.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */