4.4.3. __attribute__((transparent_union))

The transparent_union type attribute enables you to specify a transparent_union type, that is, a union data type qualified with __attribute__((transparent_union))__.

When a function is defined with a parameter having transparent union type, a call to the function with an argument of any type in the union results in the initialization of a union object whose member has the type of the passed argument and whose value is set to the value of the passed argument.

When a union data type is qualified with __attribute__((transparent_union)), the transparent union applies to all function parameters with that type.

Note

This type attribute is a GNU compiler extension that is supported by the ARM compiler.

Note

Individual function parameters might also be qualified with the corresponding __attribute__((transparent_union)) variable attribute.

Example

typedef union { int i; float f; } U __attribute__((transparent_union));

void foo(U u)
{
    static int s;
    s += u.i;    /* Use the 'int' field */
}void caller(void)
{
    foo(1);        /* u.i is set to 1 */
    foo(1.0f);     /* u.f is set to 1.0f */
}

Mode

Supported in GNU mode only.

See also

Copyright © 2007, 2010 ARM Limited. All rights reserved.ARM DUI 0348A
Non-Confidential