Heck... it's Friday night... I'm bored silly... so I'll take my poke at
the troll....
Let the record show that that The_Sage has quoted "The main function
shall have a return type of type int but otherwise in all other respects
the main functions type is implementation-defined" from the Standard. If
I recall correctly that isn't an exact quote from the Standard, but for
argument's sake I'll temporarily accept it as a close enough paraphrase.
(I don't have a copy of the Standard myself, and offhand I don't want to
go find where it had been posted before... but the paraphrase looks close
enough.)
I'm not letting get off that easy. I asked a simple, reasonable
question, so either answer the question or give us a good excuse for
not wanting to answer it...
Can you get a dictionary and look up the words "but" and "otherwise"
and tell us what they mean when applied to the sentence from the ISO
Standard that states, ""The main function shall have a return type of
type int but otherwise in all other respects the main functions type
is implementation-defined".
Here, I will even give both of you a head start...
http://www.yourdictionary.com/ahd/b/b0577100.html and
http://www.yourdictionary.com/ahd/o/o0147100.html
OK... let's look at your definitions and the statement that they are
applying to.
"otherwise". Definition 3 of your referenced dictionary: "In other
respects". Note the word "other" in there. It excludes already
mentioned aspects of a main function's type. The return type of a
function is only part of a function's type.
So... inserting the appropriate definitions in the appropriate places:
"The main function shall have a return type of type int but in all other
respects the main function's type is implementation defined"
Again, I draw your attention to the word "other". (From your favourite
dictionary:
http://www.yourdictionary.com/ahd/o/o0146800.html)
Definition 1b in particular: "Being the remaining ones of several". The
main function's type has more than one component. In particular it has
at least a return type, and a certain number, type, and order of
parameters. The first part of the sentence specifies what the return
type must be, and the second part (y'know, the stuff after the "but")
specifies what the remaining components of main's type must be.
After you are able tell us what "but otherwise" means, concentrate on
this...
See above.
So if one's compiler's documentation happens to say anywhere that
main may have the return type void then main may indeed have the
return type void
True. If the compiler accepts void main(), then you may use void main()
with that compiler.
and a program with void main() is a conforming
program.
False. Compiler acceptance is not a determining factor in whether some
piece of source code is conforming or not. That would fall back to the
Standard, which, as we see above, precludes main from returning anything
but int. And that's ignoring the fact that you're quoting a chunk of
text that's talking about C and not C++.... read the top of the page that
your quoting from:
void main() is not legal in C++ but is legal in C.
You've come to this page because you've said something similar to
void main() is not legal in the C language. main() is required
to return int.
Note that they specifically mention "the C language", and not 'the C++
language". C != C++.
This is the case for at least the following compilers:
Watcom C/C++. The C Library Reference for Watcom's C compiler says
that "the main function can be declared to return void".
Which only means that Watcom C/C++ will accept void main(). Says nothing
about whether void main() is conforming or not.
IBM VisualAge C/C++. The Language Reference for IBM VisualAge C/C++
says that main "can also be declared to return void".
Which only means that IBM Visual Age C/C++ will accept void main(). Says
nothing about whether void main() is conforming or not.
Microsoft Visual C/C++. The MSDN documentation says that main "can
be declared as returning void".
Which only means that Microsoft Visual C/C++ will accept void main().
Says nothing about whether void main() is conforming or not.
Nice elipsis that glosses over the compilers (that this document
mentions) that don't have the same compiler extensions. Not damning
evidence against you since you don't claim that compilers _must_ support
other forms of main... but an interesting choice to omit.
Other compilers are in between:
The documentation for Borland C/C++ is littered with sample programs
that define a void main() function, but it does not explicitly list
this as a legal definition of main, so - somewhat ironically - most
of the example code in Borland's documentation is non-conforming.
Sure... most of the example code in Borland's documentation is non-
conforming C++. What's your point?
The documentation for Comeau C/C++ implies that main may have a
return type other than int where it discusses the semantics of
falling off the end of main() without a return statement, but does
not explicitly specify what additional definitions of main it
allows.
Not having seen the documentation for Comeau C/C++, I can't support or
refute your claims. However, if all it does is mention that falling off
the end of main is equivalent to a "return 0;", then they have done
nothing to support that main may return anything other than int.
When this page was first published, Comeau C/C++ used void main() in
its examples as well. However, Greg Comeau was shown this web page,
and in response changed the examples to use int main(). He did not
correct the aforementioned implication, however. (Nor did he inform
me of the change. I found out only by accident.)
I wasn't aware that all vendors must publish their changes through you.
And it can simply be that they have chosen to amend their examples to
stop using a vendor-specific compiler extension in preference to using
conformant examples. I commend them on their choice to be conformant.
The documentation for Digital Mars C/C++ also uses void main() in
its examples.
http://homepages.tesco.net/~J.deBoynePollard/FGA/legality-of-void-mai
n.html
Again, you point to this page which _explictly_ refutes your claim (Hey,
_you_ supplied the page, not me. So it's reasonable to assume that you
support the content of that page as well). Look at the title. It says
in no uncertain terms that in C++, void main() is not legal. Continue
reading through the article and it is quite careful to keep stating that
void main() isn't legal in C++. What this page has to say about C is
irrelevant to this discussion (and newsgroup). You want to talk about
void main() in C? Go to a C newsgroup. This is Standard C++ only [note
that I removed the asm newsgroup]. I know the last time someone pointed
this out to you, you said something along the lines of "Ignore that, but
look at the list of compilers at the bottom which allow void main()!".
(And again, back to the argument that having a compiler accept a piece of
code does not made the code well-formed w.r.t. the Standard.)