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,