Sujet : Re: Whaddaya think?
De : jameskuyper (at) *nospam* alumni.caltech.edu (James Kuyper)
Groupes : comp.lang.cDate : 17. Jun 2024, 07:21:22
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v4okl2$flpo$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11
User-Agent : Mozilla Thunderbird
On 6/17/24 01:41, Janis Papanagnou wrote:
On 16.06.2024 22:32, Keith Thompson wrote:
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
[...] K&R at
least seems to say that 'void' can only be declared for the
return type of functions that do not return anything.
[...]
>
No version of C has ever permitted "void main" except when an
implementation documents and permits it. [...]
I cannot comment on main() being handled differently than
other C functions. I was just quoting my old copy of K&R.
It is handled differently. Your own functions can be declared in a wide
variety of ways, so long as the declaration that is relevant to function
designator in a function call is compatible with the definition of the
function that it designates.
C standard library functions can only be declared in ways compatible
with the specifications in the C standard.
main(), on the other hand, is unique, in that you have two incompatible
choices of how to define it, and an implementation can designate
additional choices. You can define main() in any way compatible with one
of the options supported by your implementation; but portable code
should define it only in one of the two ways specified by the C standard.
K&R is long obsolete; up-to-date drafts of the standard that are almost
identical to the latest version of the standard are free and easily
available.
I don't understand what you mean with "no version of C has
ever permitted", given that my C compiler doesn't complain.
He wrote "No version of C has ever permitted "void main" except when an
implementation documents and permits it." Note that he is talking about
versions of the standard, not versions of any particular implementation
of C. If your C compiler "documents and permits" "void main", then it
certainly shouldn't complain about it. However, since the C standard
does not mandate support for void main, you've no guarantee of
portability of code that uses void main to other implementations of C.