Functions without Return & Function with ONLY a return C:

Thread Starter

Jack Tranckle

Joined Jan 20, 2016
73
I have been analysing some C code (for avr ucontrollers) recently and have been slightly confused with the different purposes of these two types of functions and thought that it would be an interesting thread to discuss. Any advice would be appreciated!

A function Without a Return:

A function with only a Return:
 

Ian Rogers

Joined Dec 12, 2012
1,136
Functions returns in C are pretty much left to the individual..

Most functions return a variable type, this is good for most applications ie.. char, int or long.

When it comes to larger information ie.. strings structs etc.. your software stack start to suffer..

When you see a function that has no return, more often than not ( unless its a simple function ) has had a pointer to a variable passed to it.
The reasoning is one pointer is easier to pass than a chunk of data.. When you pass a pointer, you can actually manipulate data outside the scope of the function.. Even then it's common that a return is use , either -1 or 1 to say the function succeeded..

Each variable inside a function or passed to it needs to be stored.. On small embedded systems the software stack is only 255 bytes, even smaller, so as I said it's really down to the individual programmer how to use the function return..
 

WBahn

Joined Mar 31, 2012
32,827
Look at the C standard libraries for functions in those two categories. For example, rand() and srand().
 

spinnaker

Joined Oct 29, 2009
7,830
I have been analysing some C code (for avr ucontrollers) recently and have been slightly confused with the different purposes of these two types of functions and thought that it would be an interesting thread to discuss. Any advice would be appreciated!

A function Without a Return:

A function with only a Return:

What is your question????

All functions in C have an implied return. You do not need to explicitly specify a return. The function returns at the end of the function if there is a return defined there or not. Now it getting to the end of the function is an entirely different subject. ;)
 
Top