# 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 on other sites
Guest Anonymous Poster
probably int

##### Share on other sites
Tera_Dragon    260
If a return type is not specified then int is assumed, I think.

##### 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 on other sites
Nemesis2k2    1045
I need a definite answer, with a quote from the standard if possible. Don't worry, I'm not actually going to use this anywhere.

##### Share on other sites
Something like this?

Quote:
 ISO/IEC C++ Standardarticle 1: those ya prgram like ya do PrOn, da compilre wil say "pwnd!"

I'm not really sure if it is thre right quote [wink]

Regards

##### 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 FunctionsIn a declarationT D where D has the formD1 ( parameterdeclarationclause) cvqualifierseqoptexceptionspecificationoptand the type of the contained declaratoridin the declarationT D1 is “deriveddeclaratortypelistT,” thetype of the declaratoridin D is “deriveddeclaratortypelistfunction of (parameterdeclarationclause)cvqualifierseqopt 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 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 on other sites
Nemesis2k2    1045
Yeah, I found I couldn't find any mention of it either. I assumed the standard covered this. I guess not.

##### 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 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 on other sites
Nemesis2k2    1045
Indeed. Nice find, thanks for the help. :)

##### 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 ;)