structure function returns -- how?
notes at hcx1.UUCP
notes at hcx1.UUCP
Fri Dec 5 23:55:26 AEST 1986
Suppose a is declared as a structure and b is a function which
returns a structure. In the statement:
a = b () ;
when and how should the copying into a take place?
The pcc compilers I have seen apparently "set" b in b's stack frame.
They then return a pointer to b in that frame, and copying from that
pointer is done in a's frame. But what happens if a signal comes through
during the copy? The contents of b , which are not yet copied, are
overwritten by the signal routine's stack frame?
Another compiler overcomes this problem by passing the address of a
local structure in a's frame to the function b . Thus, instead of
"setting" b , a's local structure is filled up, and copying from that
local structure occurs when b returns.
Are there other issues to be considered?
Dave Ray -- uucp: {ucf-cs|allegra}!novavax!hcx1!daver
More information about the Comp.lang.c
mailing list