9.57 __attribute__((transparent_union)) type attribute

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 the ARM compiler supports.

Mode

Supported in GNU mode only.

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 */
}
Non-ConfidentialPDF file icon PDF versionARM DUI0375F
Copyright © 2007, 2008, 2011, 2012, 2014 ARM. All rights reserved.