Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sunybcs!boulder!ccncsu!handel.cs.colostate.edu!wendt From: wendt@handel.cs.colostate.edu (alan l wendt) Newsgroups: comp.lang.c Subject: casting to a union Message-ID: <3455@ccncsu.ColoState.EDU> Date: 13 Dec 89 00:46:39 GMT Sender: news@ccncsu.ColoState.EDU Reply-To: wendt@handel.cs.colostate.edu (alan l wendt) Organization: Colorado State University Lines: 26 Apologies if this has come up before; I don't follow this group. I have a function that accepts either char pointers or ints as arguments, so I declare it with unions, union numstr { int i; char *s; }; void foo( union numstr ns ) { ... } Why can't I call it as follows: foo((union numstr)7); Presumably foo knows which it is getting by some external means. This seems easy and innocuous, but I don't think the language will let me do it. Probably if this were allowed in, the backwards conversion would also be allowed, i.e. from (union numstr) to (int). That would be ok with me, too; I actually prefer "(int)ns" to "ns.i". Can anybody think of a reason not to allow this? Alan Wendt