Search code examples
objective-ccreturn-valueparentheses

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);
}

Solution

  • 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 ).