Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the intention of putting return values in parentheses in C/Objective-C?

I've come across some code that surrounds the return value from a method/function in parentheses.

What does that do?

The code I saw took an image, resized it and then returned it.

- (UIImage *)resizeImage:(UIImage *)image
{
    //
    // some fascinating, but irrelevant, resizing code here
    //

    return (image);
}
like image 252
Jasarien Avatar asked Dec 28 '22 06:12

Jasarien


2 Answers

At least as far as C is concerned, it makes no difference. The parens aren't necessary, but they don't change the meaning of the return statement. The grammar of the return statement is

return-statement:
    return expressionopt ;

and one of the productions of the expression non-terminal is a parenthesized-expression, or ( expression ).

like image 67
John Bode Avatar answered Dec 30 '22 19:12

John Bode


Nothing. It is completely useless.

It overrides operator precedence, yet no operator will have a lower precedence than "return".

like image 43
Tomas Avatar answered Dec 30 '22 19:12

Tomas