CF>> void main()
EL> I would do
EL> void main(void)
Even assuming the common language extension of allowing `main' to have
parameters other than `int, char**', there are two errors here, one stylistic
that you are committing yourself, and one a rather more fundamental language
error that you are both committing.
The stylistic error is in preferring "(void)" to "()". Since you are in the
C++ echo, do things as they are meant to be done in the C++ language, not as
they are meant to be done in the C language. The syntax of function
declarations is different between the C and C++ languages. Standard C
adopted the syntax of C++ almost totally when it was standardised, but had to
introduce "(void)" into the syntax of the language as a kludge, since "()" in
a function declaration already had a meaning: it implied an old-style "K&R"
function declaration.
Standard C++, on the other hand, from the start was not backwards compatible
with "K&R" function declarations, does not support such declarations, has
always required full "function prototypes", and so has no need for a kludge
to the language syntax. Yes, Standard C++ supports "(void)" for
compatibility with Standard C, but in Standard C++ the logical way to declare
a function that takes no arguments is *to have an empty parameter list*, i.e.
"()".
The recommendation to use "(void)" instead of "()" is valid in Standard C,
because the two actually mean two different things, with the former implying
type checking and the latter implying *no* type checking. This
recommentation *shouldn't*, however, be carried across to Standard C++, since
the two forms mean *exactly the same thing* in the C++ language, and "()" is
in fact more logically consistent with the rest of the language syntax than
"(void)" is.
The more fundamental language error that you both made is that the `main'
function must return an integer. Although many C++ implementations for
various PC operating systems *allow* one to declare `main' with return types
other than `int' without complaint, strictly speaking they *should* complain,
because those same implementations *expect* an `int' to be returned from
`main', since they pass that value to the operating system as the exit code
from the program.
The flaw, of course, is in those implementations. If they were to allow
`void main()' as an extension to the C++ language, then they should
*properly* allow for no return value. As things stand, they allow people to
compile programs, without complaint, whose behaviour (in terms of the result
that they return to the operating system) cannot be defined.
¯ JdeBP ®
--- FleetStreet 1.19 NR
---------------
* Origin: JdeBP's point, using Squish (2:440/4.3)
|