scalar return:通常情況,不用多說(shuō)了 http://gcc.gnu.org/onlinedocs/gc ... .html#Scalar-Return
17.10.8 How Scalar Function Values Are Returned
This section discusses the macros that control returning scalars as values—values that can fit in registers. ......
aggregate return:返回復(fù)合數(shù)據(jù)結(jié)構(gòu),caller要傳遞返回?cái)?shù)據(jù)存放的地址給callee http://gcc.gnu.org/onlinedocs/gccint/Aggregate-Return.html
17.10.9 How Large Values Are Returned
When a function value's mode is BLKmode (and in some other cases), the value is not returned according to TARGET_FUNCTION_VALUE (see Scalar Return). Instead, the caller passes the address of a block of memory in which the value should be stored. This address is called the structure value address.
稍微再?gòu)?fù)雜化一點(diǎn),gcc對(duì)于后者也就是aggregate return又做了處理,提供了兩個(gè)編譯選項(xiàng),默認(rèn)的-fpcc-struct-return就是按照前面的說(shuō)法做的,-freg-struct-return則是盡量用寄存器來(lái)存放返回值,效率可能高一點(diǎn)點(diǎn),但是可能存在與其他編譯器不兼容的情況。選項(xiàng)的解釋如下:
-fpcc-struct-return
Return “short” struct and union values in memory like longer ones, rather than in registers. This convention is less efficient, but it has the advantage of allowing intercallability between GCC-compiled files and files compiled with other compilers, particularly the Portable C Compiler (pcc).
The precise convention for returning structures in memory depends on the target configuration macros.
Short structures and unions are those whose size and alignment match that of some integer type.
Warning: code compiled with the -fpcc-struct-return switch is not binary compatible with code compiled with the -freg-struct-return switch. Use it to conform to a non-default application binary interface.
-freg-struct-return
Return struct and union values in registers when possible. This is more efficient for small structures than -fpcc-struct-return.
If you specify neither -fpcc-struct-return nor -freg-struct-return, GCC defaults to whichever convention is standard for the target. If there is no standard convention, GCC defaults to -fpcc-struct-return, except on targets where GCC is the principal compiler. In those cases, we can choose the standard, and we chose the more efficient register return alternative.
Warning: code compiled with the -freg-struct-return switch is not binary compatible with code compiled with the -fpcc-struct-return switch. Use it to conform to a non-default application binary interface.