Foo()
{
}
C++ standards question
If a function has no return type specified, what does the C++ standard say the return type will be assumed to be? Eg:
What should the return type of Foo() be assumed to be?
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.
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.
Something like this?
I'm not really sure if it is thre right quote [wink]
Regards
Quote:ISO/IEC C++ Standard
article 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
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
and from a quick glance I don't find any exceptions to that.
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.
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.
Yeah, I found I couldn't find any mention of it either. I assumed the standard covered this. I guess not.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement