190075Sobrien@c Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2132718Skan@c 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. 390075Sobrien@c This is part of the GCC manual. 490075Sobrien@c For copying conditions, see the file gcc.texi. 590075Sobrien 690075Sobrien@node Interface 790075Sobrien@chapter Interfacing to GCC Output 890075Sobrien@cindex interfacing to GCC output 990075Sobrien@cindex run-time conventions 1090075Sobrien@cindex function call conventions 1190075Sobrien@cindex conventions, run-time 1290075Sobrien 1390075SobrienGCC is normally configured to use the same function calling convention 1490075Sobriennormally in use on the target system. This is done with the 1590075Sobrienmachine-description macros described (@pxref{Target Macros}). 1690075Sobrien 1790075Sobrien@cindex unions, returning 1890075Sobrien@cindex structures, returning 1990075Sobrien@cindex returning structures and unions 2090075SobrienHowever, returning of structure and union values is done differently on 2190075Sobriensome target machines. As a result, functions compiled with PCC 2290075Sobrienreturning such types cannot be called from code compiled with GCC, 2390075Sobrienand vice versa. This does not cause trouble often because few Unix 2490075Sobrienlibrary routines return structures or unions. 2590075Sobrien 2690075SobrienGCC code returns structures and unions that are 1, 2, 4 or 8 bytes 2790075Sobrienlong in the same registers used for @code{int} or @code{double} return 2890075Sobrienvalues. (GCC typically allocates variables of such types in 2990075Sobrienregisters also.) Structures and unions of other sizes are returned by 3090075Sobrienstoring them into an address passed by the caller (usually in a 31132718Skanregister). The target hook @code{TARGET_STRUCT_VALUE_RTX} 32132718Skantells GCC where to pass this address. 3390075Sobrien 3490075SobrienBy contrast, PCC on most target machines returns structures and unions 3590075Sobrienof any size by copying the data into an area of static storage, and then 3690075Sobrienreturning the address of that storage as if it were a pointer value. 3790075SobrienThe caller must copy the data from that memory area to the place where 3890075Sobrienthe value is wanted. This is slower than the method used by GCC, and 3990075Sobrienfails to be reentrant. 4090075Sobrien 4190075SobrienOn some target machines, such as RISC machines and the 80386, the 4290075Sobrienstandard system convention is to pass to the subroutine the address of 4390075Sobrienwhere to return the value. On these machines, GCC has been 4490075Sobrienconfigured to be compatible with the standard compiler, when this method 4590075Sobrienis used. It may not be compatible for structures of 1, 2, 4 or 8 bytes. 4690075Sobrien 4790075Sobrien@cindex argument passing 4890075Sobrien@cindex passing arguments 4990075SobrienGCC uses the system's standard convention for passing arguments. On 5090075Sobriensome machines, the first few arguments are passed in registers; in 5190075Sobrienothers, all are passed on the stack. It would be possible to use 5290075Sobrienregisters for argument passing on any machine, and this would probably 5390075Sobrienresult in a significant speedup. But the result would be complete 5490075Sobrienincompatibility with code that follows the standard convention. So this 5590075Sobrienchange is practical only if you are switching to GCC as the sole C 5690075Sobriencompiler for the system. We may implement register argument passing on 5790075Sobriencertain machines once we have a complete GNU system so that we can 5890075Sobriencompile the libraries with GCC@. 5990075Sobrien 60117395SkanOn some machines (particularly the SPARC), certain types of arguments 6190075Sobrienare passed ``by invisible reference''. This means that the value is 6290075Sobrienstored in memory, and the address of the memory location is passed to 6390075Sobrienthe subroutine. 6490075Sobrien 6590075Sobrien@cindex @code{longjmp} and automatic variables 6690075SobrienIf you use @code{longjmp}, beware of automatic variables. ISO C says that 6790075Sobrienautomatic variables that are not declared @code{volatile} have undefined 6890075Sobrienvalues after a @code{longjmp}. And this is all GCC promises to do, 6990075Sobrienbecause it is very difficult to restore register variables correctly, and 7090075Sobrienone of GCC's features is that it can put variables in registers without 7190075Sobrienyour asking it to. 72