You'll notice that many of the answers were all but identical. They say tha= t great minds think alike (and that fools seldom differ) :-) -- Bob Ammerman RAm Systems=20 -----Original Message----- From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf Of Bob Blick Sent: Wednesday, January 16, 2013 10:51 PM To: Microcontroller discussion list - Public. Subject: Re: [PIC] for the C experts Thanks Isaac and everyone else for the great replies. I'm going to try it and see what the disassembly looks like! Best regards, Bob On Wed, Jan 16, 2013, at 05:44 PM, Isaac Marino Bavaresco wrote: > First, define a named type: >=20 > typedef union > { > unsigned int uint; > signed int ssint; > unsigned char[2] unchar > } mytype_t; >=20 >=20 > Second, declare and implement the function correctly. It is not=20 > allowed to declare a parameter without type: >=20 > void myDumbFunction( mytype_t somevar ) > { > if( somevar.unchar[1] ) > do_something(); > } >=20 >=20 > Third, declare a variable with the correct type, initialize it and=20 > call the function: >=20 > mytype_t dumbvar; >=20 > // (in your example you used an "unsigned int" variable as argument,=20 > so we will initialize the field of the same type) > dumbvar.uint =3D somedumbvalue; >=20 > myDumbFunction( dumbvar ); >=20 >=20 > Best regards, >=20 > Isaac >=20 >=20 >=20 > Em 16/1/2013 22:01, Bob Blick escreveu: > > Is this a correct way to declare and call a function that uses a=20 > > 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;=20 > > 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=20 > > unsigned int(not that it should matter since it's just memory space=20 > > that is the size of the union), so within my function I can access=20 > > somevar.uint somevar.ssint as well as somevar.unchar[0] and=20 > > somevar.unchar[1] > > > > That all seem OK? I know that in most cases using a union serves no=20 > > 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=20 > > correct if it isn't. > > > > Thanks, > > > > Bob -- http://www.fastmail.fm - mmm... Fastmail... -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membershi= p options at http://mailman.mit.edu/mailman/listinfo/piclist --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .