Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does `rc` for function return values mean? [closed]

Tags:

c

return-value

When reading C code, I often come across statements such as:

int rc = foo(bar, baz);
assert(rc != NULL);

where the variable rc is used for checking the return value of the function. I assume it's a mnemonic of some sort but can't deduce its meaning.

I would like to know its meaning to help with my understanding of the code.

like image 834
krm Avatar asked Feb 26 '13 14:02

krm


2 Answers

I think it's "return code". Mostly used to refer to integer return codes of 0/NULL or 1 form.

like image 78
favoretti Avatar answered Oct 10 '22 08:10

favoretti


rc stands for "rutabaga casserole". What? You don't think so?!

Well the fact is no one can say what this really stands for because there are no mandated names in C code. It could stand for "return code" or "remote control" or whatever the author had in his head at the time.

I would like to know it's meaning to help with my understanding of the code

Your argument is inherently flawed. If you want to understand code better, make sure you read the documentation and source of the functions being used, never trust that the names of functions, or data types yield any precedence into what the code is actually doing.


Edit to address the comment:

Actually, I think your argument is flawed, Mike. It is absurd to say that knowing commonly used variable names won't help you understand code, despite the fact that they are not mandated. For example, it is well known that i is commonly used (but not mandated) as a loop increment variable across all languages.

It's a fair argument to say that there are indeed variable names that people tend to follow. We'll see ret or rc for a return value or a return code, frequently we'll see single variables a,b,c,...,i,j,k, used for looping operators. However making an assumption about what a variable does based on a name is a terrible idea.
Not only might your assumption about what the variable stands for be wrong (for example a simple i in an Ohm's law function might very well be the name chosen to represent current, nothing to do with looping) but also what makes sense to you might not be what made sense to the author.

example, the author has a variable int return_code. You might assume that's going to house the return code of the function, but maybe it's being used to check the returned value of a function called within the function you're evaluating and the variable int r is used for the return code instead.
Let's say you see the variable count is that going to be a loop iterator, or a count of a number of files, or is it a counting semaphore?

So, Chris Redford, I must respectfully disagree. It's not absurd to say that knowing commonly used variable names won't help understand code, because it won't do any better than reading the code itself, and it might lead you down a stray path thinking you know what is going on when you really don't.
If you understand source code you'll see return xxx; or for(int yyy=0; and you won't have to make assumptions about what those variables are doing, you'll know for sure, and that's the only way to be guaranteed you know what's happening.

like image 23
Mike Avatar answered Oct 10 '22 08:10

Mike