I'm not quite sure I follow the question, but... If I wanted to do the same thing with a structure, I would pass a=20 pointer to the stucture (even if it were simply a byte array) into a=20 function that takes a void * pointer as a parameter. I would then cast=20 the pointer within the function. typedef union tagFoonion { unsigned char bytes[2]; unsigned int word_u16; } Foonion; char theBytes[2]; Foonion gUnion; gUnion.bytes[0] =3D 0xbe; gUnion bytes[1] =3D 0xba; memcpy(theBytes, &gUnion, sizeof(Foonion)); useUnion(theBytes); // pass bytes as union ... void useUnion(void * anArg) { Foonion *pUnion =3D (Foonion *) anArg; Foonion myUnion; memcpy(myUnion, pUnion, sizeof(Foonion)); // a local copy of // do stuff with myUnion, or even pUnion (which is gUnion) } There're probably some errors with casting or specifying pointers,=20 but it's my expression mof a general technique. Joe W On 01/16/2013 07:01 PM, Bob Blick wrote: > Is this a correct way to declare and call a function that uses a union > as the argument, and pass it a value that is not declared as union? > > //declaring the function > void myDumbFunction(union {unsigned int uint; signed int ssint; unsigned > char[2] unchar}); > > // calling it from somewhere in my program > unsigned int dumbvar; > dumbvar =3D somedumbvalue; > myDumbFunction(dumbvar); > > // the function > void myDumbFunction(somevar){ > if (somevar.unchar[1]) > do_something(); > } > > Is that going to work, the compiler should know that somevar is an > unsigned int(not that it should matter since it's just memory space that > is the size of the union), so within my function I can access > somevar.uint somevar.ssint as well as somevar.unchar[0] and > somevar.unchar[1] > > That all seem OK? I know that in most cases using a union serves no real > purpose other than to be dangerous, there are other ways to do things. > But my question is whether this is accurate or how it would be made > correct if it isn't. > > Thanks, > > Bob > --=20 Joe Wronski Stillwater Embedded Engineering www.stillwatereng.net --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .