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

  • Home
  • SEARCH
  • 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 918597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:24:13+00:00 2026-05-15T18:24:13+00:00

what is considered best practice in the following snippet: int foo(struct data *bar, struct

  • 0

what is considered best practice in the following snippet:

int foo(struct data *bar, struct info bla) {
    if (!bar) {
        bla->status = 0;
        return;
    }
    ...
}

in fact, it works fine. but i’m feeling uncomfortable with gcc giving me a warning.


here is the actual code:

static int pop(struct stack **stack, struct info *info) {
        int ret;
        struct stack *tmp;

        if (!*stack) {
                info->error = 0;
                return;
        }

        ret = (*stack)->data;
        tmp = *stack;
        *stack = (*stack)->next;
        free(tmp);

        return ret;
}
  • 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-15T18:24:13+00:00Added an answer on May 15, 2026 at 6:24 pm

    Best practice is not to write code like that. If you can’t return an integer of some sort at that point, you need to redesign your code. Note that the function as written will return a value of some sort to the calling code – you just don’t know what that value will be.

    The classic way round this is to return the value via a pointer parameter, with the actual function returning a status:

    int f( int * p ) {
       if ( bad ) {
           return 0;   // fail indicator
       }
       else {
          * p = 42;    // integer return value
          return 1;    // success indicator
       }
    }
    

    Edit: In the code you posted you are manipulating a stack. Popping an empty stack is undefined behaviour for all stacks I know, so you can just return any integer that takes your fancy (I would return 0) and document the behaviour.

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

Sidebar

Related Questions

which of the following syntax is considered best practice? For<IMyInterface>().LifecycleIs(new HybridLifecycle()).Use<MyImplementation>(); For<IMyInterface>().LifecycleIs(Lifecycles.GetLifecycle(InstanceScope.Hybrid)).Use<MyImplementation>(); if the
Is there a way in Cocoa that is currently considered best practice for creating
What is considered as best practice when it comes to assemblies and releases? I
With Zend_Framework, I wondered what is considered best practice for building up the content
Is using one database column for each attribute in an ER-model considered best practice?
Is it considered best practice to use file appenders or database appenders in log4net?
What would you consider best practice for organizing JUnit tests in a project, and
What do you consider best practice when it comes to error handling errors in
It's widely considered that the best reason to validate one's HTML is to ensure
The following practice is fairly commonplace in the inline JavaScript I have to work

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.