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