Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 988375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:37:43+00:00 2026-05-16T05:37:43+00:00

I just had some weird behavior from a version of g++ for Windows that

  • 0

I just had some weird behavior from a version of g++ for Windows that I got with Strawberry Perl. It allowed me to omit a return statement.

I have a member function that returns a structure consisting of two pointers, called a boundTag:

struct boundTag Box::getBound(int side) {
    struct boundTag retBoundTag;
    retBoundTag.box = this;
    switch (side)
    {
        // set retBoundTag.bound based on value of "side"
    }
}

This function gave me some bad output, and I discovered that it had no return statement. I had meant to return retBoundTag but forgot to actually write the return statement. Once I added return retBoundTag; everything was fine.

But I had tested this function and gotten correct boundTag output from it. Even now, when I remove the return statement, g++ compiles it without warning. WTF? Does it guess to return retBoundTag?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:37:44+00:00Added an answer on May 16, 2026 at 5:37 am

    Omitting the return statement in a non-void function [Except main()] and using the returned value in your code invokes Undefined Behaviour.

    ISO C++-98[Section 6.6.3/2]

    A return statement with an expression can be used
    only in functions returning a value; the value of the expression is
    returned to the caller of the function. If required, the expression
    is implicitly converted to the return type of the function in which it
    appears. A return statement can involve the construction and copy of
    a temporary object (class.temporary). Flowing off the end of a
    function is equivalent to a return with no value; this results in
    undefined behavior in a value-returning function
    .

    For example

    int func()
    {
        int a=10;
        //do something with 'a'
        //oops no return statement
    }
    
    
    int main()
    {
         int p=func();
         //using p is dangerous now
         //return statement is optional here 
    }
    

    Generally g++ gives a warning: control reaches end of non-void function. Try compiling with -Wall option.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ive just had some fantastic help from Sandeepan, thank you! Please can anyone see
I just had the odd case that my Android project for some reason would
I just had some basic php questions to further my understanding as I learn,
I just had a conversation with my lead developer who disagreed that unit tests
I had been steering away from C# for a while, because it was just
I had some time and decided to implement a one time pad just for
It might be a lack of coffee, but I've just had some, so I'll
Simple problem... I had some comments on my code and deleted them and got
I've just had to write a string reverse function in C# 2.0 (i.e. LINQ
I'm an MFC programmer. I just had my first taste of Vista (on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.