Sign in to follow this  
Nemesis2k2

C++ standards question

Recommended Posts

Nemesis2k2    1045
If a function has no return type specified, what does the C++ standard say the return type will be assumed to be? Eg:
Foo()
{
}
What should the return type of Foo() be assumed to be?

Share this post


Link to post
Share on other sites
Rattrap    3385
I believe in int is assumed. Now I know Microsoft Visual C++ really frowns on not defining a return type (not that it completely conforms to the standard). Plus at that point it assumes something is going to be returned, and if you don't define something, what maybe returned is undefined.

Share this post


Link to post
Share on other sites
I would say that the program is ill-formed the assumption about return type is a C left-over that's no longer in the language

Quote:
§8.3.5 Functions

In a declarationT D where D has the form
D1 ( parameterdeclarationclause
) cvqualifierseqopt
exceptionspecificationopt
and the type of the contained declaratorid
in the declarationT D1 is “deriveddeclaratortypelist
T,” the
type of the declaratorid
in D is “deriveddeclaratortypelist
function of (parameterdeclarationclause)
cvqualifierseq
opt returning T”; a type of this form is a function type.

and from a quick glance I don't find any exceptions to that.

Share this post


Link to post
Share on other sites
Nemesis2k2    1045
Nevermind, it's sorted. I thought I was getting mixed messages from my IDE about what the return type was going to be, but I was interpreting it incorrectly. It does appear the assumed return type is int, which is what I thought it should be.

Share this post


Link to post
Share on other sites
microdot    324
Quote:
-7- Declarations

-7- Only in function declarations for constructors, destructors, and type conversions can the decl-specifier-seq be omitted.*

[Footnote: The ``implicit int'' rule of C is no longer supported. --- end foonote]


Perhaps this is what you're looking for.

Share this post


Link to post
Share on other sites
Quote:
Original post by microdot
Quote:
-7- Declarations
-7- Only in function declarations for constructors, destructors, and type conversions can the decl-specifier-seq be omitted.*

[Footnote: The ``implicit int'' rule of C is no longer supported. --- end foonote]


Perhaps this is what you're looking for.


I think we have a winner!!

Share this post


Link to post
Share on other sites
Quote:
Original post by DigitalDelusion
Quote:
Original post by microdot
Quote:
-7- Declarations
-7- Only in function declarations for constructors, destructors, and type conversions can the decl-specifier-seq be omitted.*

[Footnote: The ``implicit int'' rule of C is no longer supported. --- end foonote]


Perhaps this is what you're looking for.


I think we have a winner!!


Mine was just a little more obscure... :'(

Regards ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this