R
Richard Harter
There is probably a simple way to do what I want but I don't see
it. Any suggestions are welcome.
Suppose I have a function foo with an argument that can be any of
several types and that I want to use a union for that argument.
In a header file there is the following:
#define VAL_ALT union urt_value_alt
.....
VAL_ALT {
int is_int; /* Value is an integer */
void * is_ptr; /* Value is a pointer */
};
.....
URT_RET urtree_insert (URT_HANDLE *, unsigned char *, long, VAL_ALT,int);
In a C file I want to call urtree_insert. The relevant code is:
VAL_ALT id;
.....
dat[1] = "baaaaa";
.....
id.is_int = 2;(void) urtree_insert(root,dat[1],6,id,1);
What I would like to do is pass a literal value instead of id,
e.g., something like:
urtree_insert(root,dat[1],6,2,1);
However that won't do; the compiler rightly complains about a
type mismatch. Is there a cast that one can use? If so, what
does it look like? (Assume that urtree_insert already knows what
type it should be getting.)
it. Any suggestions are welcome.
Suppose I have a function foo with an argument that can be any of
several types and that I want to use a union for that argument.
In a header file there is the following:
#define VAL_ALT union urt_value_alt
.....
VAL_ALT {
int is_int; /* Value is an integer */
void * is_ptr; /* Value is a pointer */
};
.....
URT_RET urtree_insert (URT_HANDLE *, unsigned char *, long, VAL_ALT,int);
In a C file I want to call urtree_insert. The relevant code is:
VAL_ALT id;
.....
dat[1] = "baaaaa";
.....
id.is_int = 2;(void) urtree_insert(root,dat[1],6,id,1);
What I would like to do is pass a literal value instead of id,
e.g., something like:
urtree_insert(root,dat[1],6,2,1);
However that won't do; the compiler rightly complains about a
type mismatch. Is there a cast that one can use? If so, what
does it look like? (Assume that urtree_insert already knows what
type it should be getting.)