3.7.4. Cast of a union

A cast to a union type is similar to other casts, except that the type specified is a union type. You can specify the type either with a union tag or with a typedef name.

Mode

Supported in GNU mode for C90 and C99 only.

Example

typedef union
{
    double d;
    int i;
} foo_t;

int Cast_to_Union_0(int a, double b)
{
    
    foo_t u;
    if (a>100)
        u = (foo_t) a ; // automatically equivalent to u.i=a;
    else
        u = (foo_t) b ; // automatically equivalent to u.d=b;
    return u.i;    
}
Copyright © 2007, 2010 ARM Limited. All rights reserved.ARM DUI 0348A
Non-Confidential