Using a union as a function parameter

From: Juke All (me_at_here.net)
Date: 05/27/04


Date: Thu, 27 May 2004 21:01:25 GMT

When I compile the code (below), I get this error:
    cannot convert parameter 1 from 'int' to 'union dna'

Without saying:

FOO x;
x.val = 100;

...is it possible to use a union as a function parameter, and when
calling that function, pass the argument as one of the types of the
union (int, in the following case)?

typedef union foo
{
   void* ptr;
   int val;
} FOO;

void* test(FOO obj)
{
   void* ptr = obj.ptr;
   int val = obj.val;
   return NULL;
}

int main(int argc, char* argv[])
{
   int x = 100;
   test(x);
   return 0;
}