Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the point of adding a return statement at end of a void C/C++ routine?

Tags:

c++

c

I see functions/methods with a void return in the signature that have a return statement at the end of the function. What is the reason for this, and does this apply to other languages?

For all I know, I can use return if I want to exit anywhere else but the end of the function.

A C example:

void function(void)
{
   int x = 1 + 2;

   return;    // what do we need this for, if at all?
}
like image 586
dubnde Avatar asked Mar 16 '09 10:03

dubnde


2 Answers

This seems pointless here. But my guess is that this kind of thing can be used to put a breakpoint in IDEs which don't support putting a breakpoint at the closing brace and by putting a breakpoint here, some values can be checked in the watch window etc.

like image 127
Aamir Avatar answered Nov 07 '22 07:11

Aamir


Someone took a 'a function must have a single return' coding guideline too literally.

like image 16
Pete Kirkham Avatar answered Nov 07 '22 09:11

Pete Kirkham