Hello everybody...Currently I am making a simple program which only contains an input, and output code, and finally an union. The goal is how to detect type of a variable correctly. Here is the code :
1 2 3 4 5 6 7 8 9 10
union SuperVariable
{
int i;
float f;
} var;
//////
var.i = 85;
bool IsDouble = Check(); //Example : It gives "false" (integer)
var.f = 21.81f;
IsDouble = Check(); //Example : It gives "true" (decimal number)
Is there any way which can do this? Help me...
(Any help would be greatly appreciated) (^_^)
union SuperVariable
{
char c;
int i;
float f;
double d;
}var;
int main()
{
var.c = 1;
var.i = 1;
var.f = 1;
var.d = 1;
int c = sizeof(var.c);
int i = sizeof(var.i);
int f = sizeof(var.f);
int d = sizeof(var.d);
}
@Darkmaster
That will not help you knowing what type is actually being "used". If you do sizeof(var) it will always give you the same value (probably 8).