Home > other >  [discussion] about the return value types to void the return value of a function
[discussion] about the return value types to void the return value of a function

Time:05-20

I have been familiar with C language and embedded don't know much, and today an embedded development discussion C encountered such a problem,
 void f () {} 

For a return value type as the function of void
I think this function is not return a value,
And the embedded development is of opinion that all function has a return value, including void functions,
Just do not return void functions,
A man is hard to understand, since not return again how can have the return value,
And I check the assembly or check textbook, couldn't find a return value but not the description of the return,
The embedded development has been emphasized in the embedded this is common sense,

In desperation, came to this BBS consult everybody embedded predecessors,
Excuse me, are void f () {} this function is not return a value, or has a return value and not return?

CodePudding user response:

This problem is quite interesting,
Deep thinking, should be involved in function invocation mechanism,
The first thing to understand is that there is only one computer processor (early so, later multithreading is another said), the program run is a PC pointer sequentially ordered process,
And the realization of the function calls, is actually a pointer to the PC content according to the program to jump to the called function of memory address, and the function call is completed, the PC pointer also need to jump back to invoke the address before, this is the realization of a function is called
And processing business is the purpose of the function call, so the corresponding parameter, the change of the return value is the purpose of the call, and mass participation, the return value of these data is must have a register for storage, in C level, the void does not need to consider in order to return the value of storage and set up a section of memory to use, can think that there is no return value,
And embedded this, actually says is too general, is 8 bits MCU, or 16 bit MCU, or arm, even with different digits MCU architecture, because the compiler's difference, and there are many different characteristics, not all of the concept is common,
However, his this kind of idea, in the early of 8-bit MCU (51 series, for example), is understandable, because this kind of MCU, the structure is simple, the location of the return value is a fixed set of registers, so there is no return value is just not to read these registers,
Finally, the problem also appeared to be no practical significance of the application,

CodePudding user response:

reference 1st floor C_Rabbit response:
this problem is quite interesting,
Deep thinking, should be involved in function invocation mechanism,
The first thing to understand is that there is only one computer processor (early so, later multithreading is another said), the program run is a PC pointer sequentially ordered process,
And the realization of the function calls, is actually a pointer to the PC content according to the program to jump to the called function of memory address, and the function call is completed, the PC pointer also need to jump back to invoke the address before, this is the realization of a function is called
And processing business is the purpose of the function call, so the corresponding parameter, the change of the return value is the purpose of the call, and mass participation, the return value of these data is must have a register for storage, in C level, the void does not need to consider in order to return the value of storage and set up a section of memory to use, can think that there is no return value,
And embedded this, actually says is too general, is 8 bits MCU, or 16 bit MCU, or arm, even with different digits MCU architecture, because the compiler's difference, and there are many different characteristics, not all of the concept is common,
However, his this kind of idea, in the early of 8-bit MCU (51 series, for example), is understandable, because this kind of MCU, the structure is simple, the location of the return value is a fixed set of registers, so there is no return value is just not to read these registers,
Finally, the problem also appeared to be no practical significance of the application,
does not what practical significance
Just like dok activity
On the BBS is do not brag! Ha ha ha
For the location of the return value is a fixed set of registers that
Void functions also won't go to set the record of a set of registers
So a set of registers in the record should be the last time the function return values
Rather than the function return value
I understand it reasonable?
Thank you for reply

CodePudding user response:

refer to the second floor lin5161678 response:
Quote: refer to 1st floor C_Rabbit response:
this problem is quite interesting,
Deep thinking, should be involved in function invocation mechanism,
The first thing to understand is that there is only one computer processor (early so, later multithreading is another said), the program run is a PC pointer sequentially ordered process,
And the realization of the function calls, is actually a pointer to the PC content according to the program to jump to the called function of memory address, and the function call is completed, the PC pointer also need to jump back to invoke the address before, this is the realization of a function is called
And processing business is the purpose of the function call, so the corresponding parameter, the change of the return value is the purpose of the call, and mass participation, the return value of these data is must have a register for storage, in C level, the void does not need to consider in order to return the value of storage and set up a section of memory to use, can think that there is no return value,
And embedded this, actually says is too general, is 8 bits MCU, or 16 bit MCU, or arm, even with different digits MCU architecture, because the compiler's difference, and there are many different characteristics, not all of the concept is common,
However, his this kind of idea, in the early of 8-bit MCU (51 series, for example), is understandable, because this kind of MCU, the structure is simple, the location of the return value is a fixed set of registers, so there is no return value is just not to read these registers,
Finally, the problem also appeared to be no practical significance of the application,
does not what practical significance
Just like dok activity
On the BBS is do not brag! Ha ha ha
For the location of the return value is a fixed set of registers that
Void functions also won't go to set the record of a set of registers
So a set of registers in the record should be the last time the function return values
Rather than the function return value
I understand it reasonable?
Thank you


Yes, without a return value of function, if the return value of the register is fixed, where the data are meaningless (also is not necessarily the last call return values, because register may be changed by other factors)

CodePudding user response:

There is no return value,
Returns a value, to the specified register save the return value,
The void will not have this operation,

CodePudding user response:

In the process of learning, found the suspect to think, to assume that, to discuss, to deny to promote scientific progress,

Newton's apple hit, if only blame their bad luck, standing in the wrong position, the discovery of gravity will be pushed back N years

CodePudding user response:

refer to the original poster lin5161678 response:
I have been familiar with C language and don't know much about the embedded, and an embedded development discussion C today when encountered such a problem,
 void f () {} 

For a return value type as the function of void
I think this function is not return a value,
And the embedded development is of opinion that all function has a return value, including void functions,
Just do not return void functions,
A man is hard to understand, since not return again how can have the return value,
And I check the assembly or check textbook, couldn't find a return value but not the description of the return,
The embedded development has been emphasized in the embedded this is common sense,

In desperation, came to this BBS consult everybody embedded predecessors,
Excuse me, are void f () {} this function is not return a value, or has a return value and not return?


All the return value should be understood as the logical level, despite the logic about the return value has no meaning!
Understand first what is the return value:
If the assembler programming, is likely to run a result value, save to a register or storage, the function by RET instruction after return, you can choose to use the value or not in registers or memory use, this is returned by the function; As you function does not define the return value, then should not save the results to the register or memory, in the position, the use of such value is meaningful;
General if is C or C + + programming, function parameters and return values passed through the stack and returns a function, there will be a return value of stack space, with no return value of functions, the compiler does not generally assign the return value space;

Other languages, too, a function of void, there would be no return value,
  • Related