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;
}
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:
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.