
Function Structure and Calling Conventions
6-17
Run-Time Environment
6.3.3.1 Returning a structure
If the function returns a structure, the caller (parent function) allocates space
for the structure and then passes the address of the return space to the called
function (child function) as an additional and final argument on the stack. To
return a structure, the called function then copies the structure to the memory
block pointed to by this argument. If the caller does not use the return value,
the value of the argument is 0. This directs the called function not to copy the
return structure.
In this way, the caller can accurately tell the called function where to return the
structure. For example, in the statement s = f(), where
s is a structure and f is
a function that returns a structure, the caller can simply pass the address of
s as the last argument and call f. Function f then copies the return structure
directly into s, performing the assignment automatically.
You must be careful to properly declare functions that return structures, both
at the point where they are called (so the caller passes the address of the
return space as the last argument) and where they are defined (so the function
knows to copy the result).
6.3.3.2 Not moving the return address to the software stack
If this function calls no other functions, or if the only functions called are from
a list of run-time-support functions the compiler knows will not exceed a call
depth of 8, then there is no need to pop the return address off of the hardware
stack and push it on the software stack. Steps 2 and 12 of section 6.3.2,
How
a Called Function Responds
6.3.3.3 Not allocating a local frame
If there are no local variables, no arguments, no use of the temporary location
pointed to by AR0, the code is not being compiled to run under the debugger,
and the function does not return a structure, there is no need to allocate a local
frame. Steps 3, 4, 10, and 11 of section 6.3.2,
How a Called Function
Responds,
on
page 6-15, are omitted. If the return address is saved on the
software stack and no registers are saved on the stack, step 10 is replaced by
a MAR *
−
to point the SP to the saved return address.
Содержание TMS320C2x
Страница 8: ...viii...
Страница 69: ...2 47 C Compiler Description...
Страница 159: ...6 36...
Страница 226: ...8 6...
Страница 250: ...Index Index 14 Z z shell option 2 2 2 4 2 14 overriding with c option 4 5 overriding with n option 2 13...