Discussion:
About main()
(too old to reply)
Vladimir Grigoriev
2010-02-15 15:12:28 UTC
Permalink
In the C++standard there is the following text (3.6.1.2)
"An implementation shall not predefine the main function. This function
shall not be overloaded. It shall

have a return type of type int, but otherwise its type is
implementation-defined."



What does mean "otherwise"? Does it mean that the main may return void?



Vladimir Grigoriev
Igor Tandetnik
2010-02-15 15:18:30 UTC
Permalink
Post by Vladimir Grigoriev
In the C++standard there is the following text (3.6.1.2)
"An implementation shall not predefine the main function. This function
shall not be overloaded. It shall
have a return type of type int, but otherwise its type is
implementation-defined."
What does mean "otherwise"? Does it mean that the main may return void?
"Its" here means "the function's". The type of the function comprises its return type and the number and types of its parameters. So, the return type should be int, but the number and types of parameters are implementation-defined.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
Vladimir Grigoriev
2010-02-15 15:31:07 UTC
Permalink
Thanks, Igor. I could not understand this part of the phrase.

Vladimir Grigoriev
Post by Vladimir Grigoriev
In the C++standard there is the following text (3.6.1.2)
"An implementation shall not predefine the main function. This function
shall not be overloaded. It shall
have a return type of type int, but otherwise its type is
implementation-defined."
What does mean "otherwise"? Does it mean that the main may return void?
"Its" here means "the function's". The type of the function comprises its
return type and the number and types of its parameters. So, the return type
should be int, but the number and types of parameters are
implementation-defined.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily
a good idea. It is hard to be sure where they are going to land, and it
could be dangerous sitting under them as they fly overhead. -- RFC 1925
Duane Hebert
2010-02-15 18:11:09 UTC
Permalink
Post by Vladimir Grigoriev
Thanks, Igor. I could not understand this part of the phrase.
This question comes up quite often. It's a shame that they didn't use Igor's
terminology instead...
Vladimir Grigoriev
2010-02-15 19:19:14 UTC
Permalink
I have reread the phrase and I have understood that "but otherwise its type
is
implementation-defined." says about the type of the function not about the
return type.:)

Vladimir Grigoriev
Post by Duane Hebert
Post by Vladimir Grigoriev
Thanks, Igor. I could not understand this part of the phrase.
This question comes up quite often. It's a shame that they didn't use
Igor's terminology instead...
Duane Hebert
2010-02-15 20:08:12 UTC
Permalink
Post by Vladimir Grigoriev
I have reread the phrase and I have understood that "but otherwise its type
is
implementation-defined." says about the type of the function not about the
return type.:)
That's right. But it could just as well say that it must return an int but
it's argument list can be implementation defined....

Referring to a function's "type" is a bit obscure I think.
Victor Bazarov
2010-02-15 20:24:16 UTC
Permalink
Post by Duane Hebert
Post by Vladimir Grigoriev
I have reread the phrase and I have understood that "but otherwise its
type is
implementation-defined." says about the type of the function not about
the return type.:)
That's right. But it could just as well say that it must return an int
but it's argument list can be implementation defined....
Referring to a function's "type" is a bit obscure I think.
Using the "technical" terminology in the Standard document (as opposed
to understandable by most, "easy", speak) at least leaves enough room
for folks to write books explaining the Standard. Otherwise schildts
would have nothing to write about - anybody could simply read the
Standard and understand it.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Duane Hebert
2010-02-15 20:38:33 UTC
Permalink
Post by Victor Bazarov
Post by Duane Hebert
Post by Vladimir Grigoriev
I have reread the phrase and I have understood that "but otherwise its
type is
implementation-defined." says about the type of the function not about
the return type.:)
That's right. But it could just as well say that it must return an int
but it's argument list can be implementation defined....
Referring to a function's "type" is a bit obscure I think.
Using the "technical" terminology in the Standard document (as opposed
to understandable by most, "easy", speak) at least leaves enough room
for folks to write books explaining the Standard. Otherwise schildts
would have nothing to write about - anybody could simply read the
Standard and understand it.
Right. Sort of like making the tax laws obscure in order to create jobs for
tax consultants.
Ben Voigt [C++ MVP]
2010-02-17 22:17:52 UTC
Permalink
Post by Igor Tandetnik
"Its" here means "the function's". The type of the function comprises
its return type and the number and types of its parameters. So, the
return type should be int, but the number and types of parameters are
implementation-defined.
I think the type of the function would also include calling convention.
Stephan T. Lavavej [MSFT]
2010-02-17 22:43:13 UTC
Permalink
The Standard doesn't recognize the existence of calling conventions (and
rightfully so, as calling conventions plural are the bane of humanity).

In the (obnoxiously calling-convention-infested) real world, calling
conventions are part of function types and function pointer types. This is
why TR1 <functional> didn't work with non-default calling conventions until
VC10, when I took several days to properly overload and specialize our
machinery for each possible calling convention on each platform and
configuration.

STL
Post by Ben Voigt [C++ MVP]
Post by Igor Tandetnik
"Its" here means "the function's". The type of the function comprises
its return type and the number and types of its parameters. So, the
return type should be int, but the number and types of parameters are
implementation-defined.
I think the type of the function would also include calling convention.
Igor Tandetnik
2010-02-17 22:39:19 UTC
Permalink
Post by Ben Voigt [C++ MVP]
Post by Igor Tandetnik
"Its" here means "the function's". The type of the function comprises
its return type and the number and types of its parameters. So, the
return type should be int, but the number and types of parameters are
implementation-defined.
I think the type of the function would also include calling
convention.
C or C++ standards don't have the notion of a calling convention. C++ has a somewhat related notion of language linkage (as in, extern "C"), which is indeed part of the function type.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
Loading...