Click here to Skip to main content
15,887,267 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
AnswerRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? PinPopular
0x01AA21-Dec-23 2:50
mve0x01AA21-Dec-23 2:50 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
k505421-Dec-23 4:14
mvek505421-Dec-23 4:14 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
Bruno van Dooren21-Dec-23 21:59
mvaBruno van Dooren21-Dec-23 21:59 
AnswerRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
CPallini21-Dec-23 2:54
mveCPallini21-Dec-23 2:54 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
obermd21-Dec-23 3:44
obermd21-Dec-23 3:44 
AnswerRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
Amarnath S21-Dec-23 2:56
professionalAmarnath S21-Dec-23 2:56 
AnswerRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
Mircea Neacsu21-Dec-23 3:05
Mircea Neacsu21-Dec-23 3:05 
AnswerRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
jschell21-Dec-23 4:11
jschell21-Dec-23 4:11 
Maximilien wrote:
Was it necessary at some point in time ?


Both forms are specifically allowed then and now.

From "C Programming Language" 2nd Edition (oldest I have and copyright is 1978.)

"A function need not return a value; a return statement with no expression causes control, but no useful value, to be returned to the caller, as does "falling off the end" of a function by reaching the terminating right brace."

Possible though that earlier compilers required it.

More likely though that someone liked one form or the other. Perhaps even forced that on others.
Requiring it would be fallout from methods with a return value. Older compilers would not warn on exit without a value for those. So the calling method would then end up with whatever garbage was on the call stack.

I did not find the same syntax in "The C++ Programming Language Special Edition" (Copyright 2000) but I didn't look all that hard.

There are however examples that provide two different void functions. One which exits with return and one which does not. So works for C++ also.

-----------------------------------------------------
Just for fun this is LEGAL as documented in the C++ book above.

void g(int* p);

void h(int* p) { return g(p); }


Text explains that is needed for templates.
But if I was reviewing code and saw that anywhere but a template I would mark it as an error.
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
PIEBALDconsult21-Dec-23 5:29
mvePIEBALDconsult21-Dec-23 5:29 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
Gary Wheeler21-Dec-23 6:46
Gary Wheeler21-Dec-23 6:46 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
hpcoder217-Jan-24 16:12
hpcoder217-Jan-24 16:12 
AnswerRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
PIEBALDconsult21-Dec-23 4:18
mvePIEBALDconsult21-Dec-23 4:18 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
0x01AA21-Dec-23 5:02
mve0x01AA21-Dec-23 5:02 
AnswerRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
honey the codewitch21-Dec-23 4:25
mvahoney the codewitch21-Dec-23 4:25 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
Gary Wheeler21-Dec-23 7:06
Gary Wheeler21-Dec-23 7:06 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
honey the codewitch21-Dec-23 7:08
mvahoney the codewitch21-Dec-23 7:08 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
CPallini21-Dec-23 7:41
mveCPallini21-Dec-23 7:41 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
honey the codewitch21-Dec-23 7:42
mvahoney the codewitch21-Dec-23 7:42 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
CPallini21-Dec-23 10:25
mveCPallini21-Dec-23 10:25 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
honey the codewitch21-Dec-23 10:26
mvahoney the codewitch21-Dec-23 10:26 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
megaadam21-Dec-23 11:55
professionalmegaadam21-Dec-23 11:55 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
jschell22-Dec-23 6:44
jschell22-Dec-23 6:44 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
honey the codewitch22-Dec-23 6:48
mvahoney the codewitch22-Dec-23 6:48 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
jschell22-Dec-23 6:51
jschell22-Dec-23 6:51 
AnswerRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
englebart21-Dec-23 5:28
professionalenglebart21-Dec-23 5:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.