is there any performance proscons from returning from void functions?

The compiler will always insert a RET instruction at the end of a void function (assuming it does not end by throwing an exception). An explicit return; statement here is not needed, and will have no effect.

The generated assembly in your example is identical:


(link to godbolt)

The explicit return from a function is useful to exit the function early. For example:

void foo() {

    // do some work ...

    if (/* some condition */)
    // do more work ...


CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top