Using a union as a function parameter
From: Juke All (me_at_here.net)
Date: 05/27/04
- Next message: Mark A. Odell: "Re: Using a union as a function parameter"
- Previous message: Leor Zolman: "Re: Is this right?"
- Next in thread: Mark A. Odell: "Re: Using a union as a function parameter"
- Reply: Mark A. Odell: "Re: Using a union as a function parameter"
- Reply: Martin Dickopp: "Re: Using a union as a function parameter"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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;
}
- Next message: Mark A. Odell: "Re: Using a union as a function parameter"
- Previous message: Leor Zolman: "Re: Is this right?"
- Next in thread: Mark A. Odell: "Re: Using a union as a function parameter"
- Reply: Mark A. Odell: "Re: Using a union as a function parameter"
- Reply: Martin Dickopp: "Re: Using a union as a function parameter"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]