C++ standards question

Started by
11 comments, last by Emmanuel Deloget 18 years, 10 months ago
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?
Advertisement
probably int
If a return type is not specified then int is assumed, I think.
____________________________________________________________Programmers Resource Central
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 can't believe I'm defending logic to a turing machine." - Kent Woolworth [Other Space]

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?

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

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.
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
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.
<span class="smallfont">That is not dead which can eternal lieAnd with strange aeons even death may die.   -- "The Nameless City" - H. P. Lovecraft</span>

This topic is closed to new replies.

Advertisement