Union initialization

Darren Austin austin at scallion.ucdavis.edu
Tue May 30 09:05:30 AEST 1989


Hello,
	I have an application that uses unions for one of the
major data structures.  I would like to be able to initialize one
of these unions similar to the way that you can with arrays and
structures, for example:

struct foo {
	int a;
	char b[10];
};

struct foo f = { 4, "hello" };

is allowed, but when I tried a similar method to initialize a
union, the compiler complained.  

Is there a way to initialize static unions in C?  A quick glance
at K&R didn't yield any information on the subject.  I assume
that means that it is not possible. If it isn't, are there ways
around this problem, or am I just missing something very basic?
Any help would be most appreciated, but please SEND RESPONSES TO
ME THROUGH E-MAIL.  I do not want to start another
silly/stupid question flame fest.

Thanks,
--Darren
--
--------------------------------------+-------------------------------
Darren Austin                         | Is is a mistake to think you 
UC Davis Division of Computer Science | can solve any major problem
austin at clover.ucdavis.edu	      | just with potatoes.
--------------------------------------+-------------------------------



More information about the Comp.lang.c mailing list