Jump to content
  • Advertisement
Sign in to follow this  
mike44

return 0 differ on Linux/Windows

This topic is 557 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

Hi

If I do

return 0;

on windows it immediately terminates the current function but on Linux it seems to only affect at the function end? Well it continues unlike Windows. How to immediately exit the function also on Linux?

Many thanks

 

Share this post


Link to post
Share on other sites
Advertisement

Using "return" or "return X" (where X is some value, if the function has a return value) will exit the function in all standards-compliant C++ compilers. This will cause the destructors of objects in scope to execute. It's very likely you're misunderstanding the behavior you're seeing, as it's extremely unlikely this is some kind of Linux/Windows behavioral delta on its own.

 

Please post the code in question.

Edited by Josh Petrie

Share this post


Link to post
Share on other sites
On all c-style languages, the return statement exits the current function scope.

You may mistake the console lifetime for the program lifetime.

Share this post


Link to post
Share on other sites

So return 0; should exit my while loop? It does on Windows. I'm playing around with break and return false: now without success. So there must be something else wrong with my code?

Thanks

int inith(string, string){

  while(getline(nfs, Mtmp)){

   if (Mtmp == "my"){
 ...do stuff...
   break;
   //return 0; //works on Windows
   }

Share this post


Link to post
Share on other sites

uncomment the return statement?

 

or you are not being consistent in your testing and it is hitting the break; statement and not making it to the return statement in some of your tests.

Edited by ncsu121978

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!