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 990555
In Process

The Archive Base Latest Questions

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

I recently wrote a post: Weird Error in C++ Program: Removing Printout Breaks Program

  • 0

I recently wrote a post:
Weird Error in C++ Program: Removing Printout Breaks Program

…in which I was trying to solve a seemingly baffling problem, in which removing a cout statement would break my program.

As it turned out, my problem was that I forgot to return my true/false success flag that I was later using for logic.

But apparently SOMETHING was being returned and that something was always true if I left that cout in, but would seemingly “magically” become false when I took it out.

My question for you all is:
What determines what a c++ function return when no return command is executed within the function? Is there any logic to it?

Obviously forgetting your return type is a bad idea. In this case, though, it was largely due to the nature of my program — a quick hack job. I later decided that it wasn’t worth the effort to include implement an algorithm to determine the success/failure of the function call — but accidentally left behind the code dependent on the return.

Bafflingly g++ gave me no warnings or errors when compiling the executable like so:

g++ main.cc -g -o it_util

My version is:
g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44)

Again, to save others future frustration in case they make the same silly mistake and are met with the same seemingly erratic behavior, can anyone cast light on where a function without a return gets its return value from??

Thanks!!

  • 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:57:47+00:00Added an answer on May 16, 2026 at 5:57 am

    On x86 calling conventions, the return value for integers and pointers is on the EAX register. The following is an example of that:

    int func() {
        if(0) return 5; // otherwise error C4716: 'func' : must return a value
    }
    int main() {
        int a;
        a = func();
    }
    

    Compiling with cl.exe /Zi, MSVC++10:

    push    ebp
    mov     ebp, esp
    push    ecx
    call    j_?func@@YAHXZ  ; func(void)
    mov     [ebp+a], eax ; assumes eax contains the return value
    xor     eax, eax
    mov     esp, ebp
    pop     ebp
    retn
    

    Of course, this is all undefined behavior.

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

Sidebar

Related Questions

I recently wrote a program to solve the backpack problem using python. It works
I recently wrote another post on this same topic in which I was not
I recently wrote a program that used a simple producer/consumer pattern. It initially had
I recently wrote a script which queries PyPI and downloads a package; however, the
I recently wrote a java program transforming a SVG document to HTML/ Canvas :
Recently I wrote a program to search yahoo with a given string. The string
I recently wrote a small C code which uses sockets to listen on a
I recently wrote a small app which will grab contacts from microsoft Outlook and
Recently I wrote a program using sockets in C, to connect to an HTTP
I recently wrote a c# program on framework 4, before realising the entire company

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.