Jump to content
  • Advertisement
Sign in to follow this  
Nemesis2k2

C++ standards question

This topic is 4880 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
Guest Anonymous Poster
probably int

Share this post


Link to post
Share on other sites
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 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 this post


Link to post
Share on other sites
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

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
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!