Path: utzoo!attcan!uunet!husc6!bloom-beacon!athena.mit.edu!tada From: tada@athena.mit.edu (Michael Zehr) Newsgroups: comp.lang.c Subject: Union type conversions Message-ID: <5754@bloom-beacon.MIT.EDU> Date: 13 Jun 88 15:33:58 GMT Sender: daemon@bloom-beacon.MIT.EDU Reply-To: tada@athena.mit.edu (Michael Zehr) Organization: Massachusetts Institute of Technology Lines: 35 I have question about type conversions and portability. (please dont' tell me to buy & read a manual -- i tried and still don't know if this is legal or not) I have a function that sometimes needs an int and sometimes needs a float. (At the function end, it will be able to tell how to treat the arguements.) The question I have concerns passing the values. I made a union and a function: typedef union { int integer_value; float float_value} INTEGER_OR_FLOAT; func(INTEGER_OR_FLOAT a); What i'm wondering is how to call this function. should it be: int i; float f; func( (INTEGER_OR_FLOAT) i); func( (INTEGER_OR_FLOAT) f); or should it be: INTEGER_OR_FLOAT temp; temp.integer_value = i; func(temp); temp.float_value = f; func(temp); So what it boils down to, is whether casting into a union type is legal and portable (i don't want to just play with it til it works and then discover that it only works by accident on my compiler :-). Thanks in advance for any help. -michael j zehr