Union initialization

T. William Wells bill at twwells.uucp
Sun Feb 19 04:46:19 AEST 1989


In article <816 at atanasoff.cs.iastate.edu> hascall at atanasoff.cs.iastate.edu (John Hascall) writes:
:
:   Does 'ANSI' C allow for union initialization?

Yes, two ways:

1) Initializing via the first member:

union FOO {
	int     bar;
	char    *gak;
} Bletch = { 42 };

2) Initializing from a union of compatible type:

func()
{
	union FOO frab = Bletch;

Note the brace use: braces are required for the first way and
forbidden for the second.

---
Bill
{ uunet!proxftl | novavax } !twwells!bill



More information about the Comp.lang.c mailing list