Are parentheses around the result significant in a return statement?

前端 未结 11 2244
感情败类
感情败类 2020-11-27 12:07

Is there a difference between these two statements inside a function?

bool returnValue = true;
// Code that does something
return(returnValue);
相关标签:
11条回答
  • 2020-11-27 12:38

    There is no difference.

    One reason to use parenthesis would be if you wanted to evaluate an expression before returning but in your example, there would be no reason. See:

    Parenthesis surrounding return values

    for further discussion.

    0 讨论(0)
  • 2020-11-27 12:39

    The parenthesis on the upper example are superfluous; they are effectively ignored.

    It would be the same as something like...

    int x = (5);
    

    The parenthesis here are ignored as well.

    0 讨论(0)
  • 2020-11-27 12:39

    Both are the same in your case.

    0 讨论(0)
  • 2020-11-27 12:40

    Nope there's no difference between the two, although you can include parenthesis if it makes the expression easy to read and clear.

    0 讨论(0)
  • 2020-11-27 12:41

    You're abusively slowing down the compiler!

    The presence of parenthesis not only slow down the preprocessing phase, but they generate a more complicated Abstract Syntax Tree too: more memory, more computation.


    From a semantic point of view ? They are exactly identical. Whether there are parenthesis or not the return statement will fully evaluate the expression before returning it.

    0 讨论(0)
提交回复
热议问题