4.5.7. __attribute__((transparent_union))

The transparent_union variable attribute, attached to a function parameter which is a union, means that the corresponding argument can have the type of any union member, but the argument is passed as if its type were that of the first union member.

Note

The C specification states that the value returned when a union is written as one type and read back with another is undefined. Therefore, a method of distinguishing which type a transparent_union is written in must also be passed as an argument.

Note

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

Note

You can also use this attribute on a typedef for a union data type. In this case it applies to all function parameters with that type.

Mode

Supported in GNU mode only.

Example

typedef union
{
    int myint;
    float myfloat;
} transparent_union_t;

void Variable_Attributes_transparent_union_0(transparent_union_t aUnion __attribute__ ((transparent_union)))
{
    static int aStatic;
    aStatic +=aUnion.myint;
}

void Variable_Attributes_transparent_union_1()
{
    int aLocal =0;
    float bLocal =0;
    Variable_Attributes_transparent_union_0(aLocal);
    Variable_Attributes_transparent_union_0(bLocal);
}

See also

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