J
john
Hello:
I have a simple program with a function that takes a void * parameter.
I want to be able to distinguish a type once the flow of control is
inside the body of the funtion. I am using conditional right now.
Unfortuneately the conditionals do not adequately filter the the types
that do not apply to the specific call. I could send a flag as a
second parameter, but I would rather the program dynamically recognize
the correct type. Here is the program, and output
as it sits:
// output
//the int is 10
//the double is -1.998009
//the int is 858993459
//the double is 12.600000
// note: the first double and the second int should not have made it
// note cont: past the given conditional.
// program
void process(void *x);
main() {
int i = 10;
double d = 12.6;
process(&i);
process(&d);
}
void process(void *x) {
if((int *)x) {
printf("the int is %d \n", *((int *)x) );
}
if((double *)x) {
printf("the double is %f\n", *((double *)x) );
}
}
I have a simple program with a function that takes a void * parameter.
I want to be able to distinguish a type once the flow of control is
inside the body of the funtion. I am using conditional right now.
Unfortuneately the conditionals do not adequately filter the the types
that do not apply to the specific call. I could send a flag as a
second parameter, but I would rather the program dynamically recognize
the correct type. Here is the program, and output
as it sits:
// output
//the int is 10
//the double is -1.998009
//the int is 858993459
//the double is 12.600000
// note: the first double and the second int should not have made it
// note cont: past the given conditional.
// program
void process(void *x);
main() {
int i = 10;
double d = 12.6;
process(&i);
process(&d);
}
void process(void *x) {
if((int *)x) {
printf("the int is %d \n", *((int *)x) );
}
if((double *)x) {
printf("the double is %f\n", *((double *)x) );
}
}