Search code examples
c++cc++11return

Function calls within return()


I am currently self-learning C and C++.
I couldn't find a similar question but I would like some good explanation with a focus on C and C++ design practices.

  1. Is it a good coding practice to call a function with a return type from return()?
  2. Is this something I should even be thinking of or is this a silly question to ask?

To illustrate:

bool A (blah, blah)
{
    bool a = false;
    a = B(); // B returns bool type
    return a;

    // OR

    return (B());
}
  1. Both compile and run obviously but is one better than the other in terms of some metric such as speed, memory efficient etc..?
  2. What could be the reasons to use one or the other or am I wasting my time by asking this question?

Solution

  • If you plan on doing something with the return value of B before returning from A, go ahead and store it. If the return value of B will be the return value of A, then just return B().