Quite often in ANSI C code I can see parenthesis sorrounding a single return value.
Like this:-
int foo(int x) {
if (x)
return (-1);
else
return (0);
}
Why use () around the return value in those cases? Any ideas? I can see no reason for that.
There isn't really a reason... it's just an old convention. Editor's note: There are historical reasons.
To save space, programmers would often do the final math in the return line instead of on its own line and the parens are mostly there to make it easier to see that it is a single statement that is returned, like this:
return (x+i*2);
instead of
int y = x+i*2;
return y;
The parenthesis became a habit and it stuck.