1*e4b17023SJohn Marino@c Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2*e4b17023SJohn Marino@c 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. 3*e4b17023SJohn Marino@c This is part of the GCC manual. 4*e4b17023SJohn Marino@c For copying conditions, see the file gcc.texi. 5*e4b17023SJohn Marino 6*e4b17023SJohn Marino@node Interface 7*e4b17023SJohn Marino@chapter Interfacing to GCC Output 8*e4b17023SJohn Marino@cindex interfacing to GCC output 9*e4b17023SJohn Marino@cindex run-time conventions 10*e4b17023SJohn Marino@cindex function call conventions 11*e4b17023SJohn Marino@cindex conventions, run-time 12*e4b17023SJohn Marino 13*e4b17023SJohn MarinoGCC is normally configured to use the same function calling convention 14*e4b17023SJohn Marinonormally in use on the target system. This is done with the 15*e4b17023SJohn Marinomachine-description macros described (@pxref{Target Macros}). 16*e4b17023SJohn Marino 17*e4b17023SJohn Marino@cindex unions, returning 18*e4b17023SJohn Marino@cindex structures, returning 19*e4b17023SJohn Marino@cindex returning structures and unions 20*e4b17023SJohn MarinoHowever, returning of structure and union values is done differently on 21*e4b17023SJohn Marinosome target machines. As a result, functions compiled with PCC 22*e4b17023SJohn Marinoreturning such types cannot be called from code compiled with GCC, 23*e4b17023SJohn Marinoand vice versa. This does not cause trouble often because few Unix 24*e4b17023SJohn Marinolibrary routines return structures or unions. 25*e4b17023SJohn Marino 26*e4b17023SJohn MarinoGCC code returns structures and unions that are 1, 2, 4 or 8 bytes 27*e4b17023SJohn Marinolong in the same registers used for @code{int} or @code{double} return 28*e4b17023SJohn Marinovalues. (GCC typically allocates variables of such types in 29*e4b17023SJohn Marinoregisters also.) Structures and unions of other sizes are returned by 30*e4b17023SJohn Marinostoring them into an address passed by the caller (usually in a 31*e4b17023SJohn Marinoregister). The target hook @code{TARGET_STRUCT_VALUE_RTX} 32*e4b17023SJohn Marinotells GCC where to pass this address. 33*e4b17023SJohn Marino 34*e4b17023SJohn MarinoBy contrast, PCC on most target machines returns structures and unions 35*e4b17023SJohn Marinoof any size by copying the data into an area of static storage, and then 36*e4b17023SJohn Marinoreturning the address of that storage as if it were a pointer value. 37*e4b17023SJohn MarinoThe caller must copy the data from that memory area to the place where 38*e4b17023SJohn Marinothe value is wanted. This is slower than the method used by GCC, and 39*e4b17023SJohn Marinofails to be reentrant. 40*e4b17023SJohn Marino 41*e4b17023SJohn MarinoOn some target machines, such as RISC machines and the 80386, the 42*e4b17023SJohn Marinostandard system convention is to pass to the subroutine the address of 43*e4b17023SJohn Marinowhere to return the value. On these machines, GCC has been 44*e4b17023SJohn Marinoconfigured to be compatible with the standard compiler, when this method 45*e4b17023SJohn Marinois used. It may not be compatible for structures of 1, 2, 4 or 8 bytes. 46*e4b17023SJohn Marino 47*e4b17023SJohn Marino@cindex argument passing 48*e4b17023SJohn Marino@cindex passing arguments 49*e4b17023SJohn MarinoGCC uses the system's standard convention for passing arguments. On 50*e4b17023SJohn Marinosome machines, the first few arguments are passed in registers; in 51*e4b17023SJohn Marinoothers, all are passed on the stack. It would be possible to use 52*e4b17023SJohn Marinoregisters for argument passing on any machine, and this would probably 53*e4b17023SJohn Marinoresult in a significant speedup. But the result would be complete 54*e4b17023SJohn Marinoincompatibility with code that follows the standard convention. So this 55*e4b17023SJohn Marinochange is practical only if you are switching to GCC as the sole C 56*e4b17023SJohn Marinocompiler for the system. We may implement register argument passing on 57*e4b17023SJohn Marinocertain machines once we have a complete GNU system so that we can 58*e4b17023SJohn Marinocompile the libraries with GCC@. 59*e4b17023SJohn Marino 60*e4b17023SJohn MarinoOn some machines (particularly the SPARC), certain types of arguments 61*e4b17023SJohn Marinoare passed ``by invisible reference''. This means that the value is 62*e4b17023SJohn Marinostored in memory, and the address of the memory location is passed to 63*e4b17023SJohn Marinothe subroutine. 64*e4b17023SJohn Marino 65*e4b17023SJohn Marino@cindex @code{longjmp} and automatic variables 66*e4b17023SJohn MarinoIf you use @code{longjmp}, beware of automatic variables. ISO C says that 67*e4b17023SJohn Marinoautomatic variables that are not declared @code{volatile} have undefined 68*e4b17023SJohn Marinovalues after a @code{longjmp}. And this is all GCC promises to do, 69*e4b17023SJohn Marinobecause it is very difficult to restore register variables correctly, and 70*e4b17023SJohn Marinoone of GCC's features is that it can put variables in registers without 71*e4b17023SJohn Marinoyour asking it to. 72