You copied the Doc URL to your clipboard.

__attribute__((value_in_regs)) function attribute

The value_in_regs function attribute is compatible with functions whose return type is a structure. It alters the calling convention of a function so that the returned structure is stored in the argument registers rather than being written to memory using an implicit pointer argument.


When using __attribute__((value_in_regs)), the calling convention only uses integer registers.


__attribute__((value_in_regs)) return-type function-name([argument-list]);



is the type of structure that conforms to certain restrictions.


Declaring a function __attribute__((value_in_regs)) can be useful when calling functions that return more than one result.


When targeting AArch32, the structure can be up to 16 bytes in order to fit in four 32-bit argument registers. When targeting AArch64, the structure can be up to 64 bytes in order to fit in eight 64-bit argument registers. If the structure returned by a function qualified by __attribute__((value_in_regs)) is too big, the compiler generates an error.

Each field of the structure has to fit exactly in one integer register. Therefore, the fields can only be pointers or pointer-sized integers. Anything else, including bitfields, is incompatible. Nested structures are allowed if they contain a single field whose type is pointer or pointer-sized integer. Unions can have more that one field. If the type of the return structure violates any of the above rules, then the compiler generates the corresponding error.

If a virtual function declared as __attribute__((value_in_regs)) is to be overridden, the overriding function must also be declared as __attribute__((value_in_regs)). If the functions do not match, the compiler generates an error.

A function declared as __attribute__((value_in_regs)) is not function-pointer-compatible with a normal function of the same type signature. If a pointer to a function that is declared as __attribute__((value_in_regs)) is initialized with a pointer to a function that is not declared as __attribute__((value_in_regs)), then the compiler generates a warning.


typedef struct ReturnType
    long a;
    char *b;
    union U
       int *c;
       struct S1 {short *d;} s1;
    } u;
    struct S2 {double *e;} s2;
} my_struct;

extern __attribute__((value_in_regs)) my_struct foo(long x);