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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:25:27+00:00 2026-06-12T01:25:27+00:00

I need ideas to try to make this program more readable. I think that

  • 0

I need ideas to try to make this program more readable. I think that it’s more a question about designer than other.

I have two loops:

for( ... ) {
  //... 
   for(...) {
     if(baa) {
       goto outer;
      } 
      //statements of 2-loop
    }
     //statements of 1-loop
}

it works fine, if baa has non-zero value, jump to outer label without run stataments of loop 1 and 2. But before return, I need to do some free() calls independent if goto outer was called:

 if(a != NULL) free(a);
 if(b != NULL) free(b);

but if I’m here because goto, the above code isn’t called.

And I need do the following:

   goto outer; //if normally exited from two-loops, go to outer anyway.

    outer: {
     if(a != NULL) free(a);
     if(b != NULL) free(b);
        return ret;
    }

What makes the function something like this:

char* foo(void) {
  char *ret = NULL;

  for( ... ) {
    //... 
    for(...) {
     if(baa) {
        ret = tmp_result;
        goto outer;
      } 

       //some statements of 2-loop
     }
       //some statements of 1-loop
    }

  goto outer;

  outer: {
     if(a != NULL) free(a);
     if(b != NULL) free(b);
         return ret;
  }
}

I hope this is clear. Thanks in advance.

  • 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-06-12T01:25:28+00:00Added an answer on June 12, 2026 at 1:25 am

    The outer label is ignored by the normal control flow, it’s only used as the target of the goto, so you don’t need it after the loop. Further, there is no need to group the statements after the label into a compound statement,

    char* foo(void) {
      char *ret = NULL;
    
      for( ... ) {
        //... 
        for(...) {
         if(baa) {
            ret = tmp_result;
            goto outer;
          } 
    
           //some statements of 2-loop
         }
           //some statements of 1-loop
        }
    
      outer:
         if(a != NULL) free(a);
         if(b != NULL) free(b);
         return ret;
    }
    

    does exactly the same (and is IMO a bit nicer on the eyes).

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

Sidebar

Related Questions

I will try to make this as straight forward as possible. This question does
This is different to the other questions on this topic. I'll try to make
I have no ideas how to do this, so I need your advice. I
This is a fairly simple question. Basically, I'm having a program send HardWare ID's
I am asking this question is because I need to modify an open source
Even before telling my question, will tell you that this is a very vague
I need ideas for structuring and processing data with revisions. For example, I have
I need topic ideas related to AI on which I will base my thesis.
OK, here's what I want to implement and I need your ideas : Input
I have repaired .net 4.0 but (still) cannot find: Ilasm.exe Any ideas? I need

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.