Next: , Previous: stackext, Up: Attributes

3.5 regparm

The ‘regparm’ attribute, together with the ‘stkparm’ attribute (see stkparm), can be used to fine-tune the way arguments are passed. It makes ‘GCC’ pass arguments in registers for the function for which it was used, regardless of whether the global ‘-mregparm’ option was used or not (see -mregparm).

An optional integer argument ranging from 1 to 4 indicates how many arguments of each type should be passed in registers (see -mregparm). The syntax is the following:

     void __attribute__((regparm(3))) fun(int a, char *str, char b, int c);

This will make ‘GCC’ pass ‘a’, ‘b’ and ‘c’ in ‘d0’, ‘d1’ and ‘d2’, respectively, and ‘str’ in ‘a0’.

If the argument is not provided, the value given for ‘-mregparm’ will be used (or 2 if that option was not specified, see -mregparm).

Note: There is generally no need to use this attribute unless files compiled with different calling conventions are linked together.

For compatibility with other AmigaOS ‘C’ compilers, a preprocessor symbol ‘__regargs’ is available, which expands to __attribute__((regparm)) (see Keyword macros).

The ‘regparm’ attribute is mutually exclusive with the ‘stkparm’ attribute (see stkparm).

This attribute is necessary both in function declarations (prototypes) and definitions (function code).

This attribute was first made available in the ‘GCC’, ‘Geek Gadgets’ snapshot ‘961012’.