C
candy_init
I recently came across the following CAST macro which can cast anything
to any other thing:
#define CAST(new_type,old_object) (*((new_type *)&old_object))
union
{
char ch[4];
int i[2];
} my_union;
long longvar;
longvar = (long)my_union; Illegal cast
//////////////// ILLEGAL
longvar = CAST(long, my_union); Legal cast
I understands that why the CAST macro works but I cannot understands
that what is the problem in the following casting :
longvar = (long)my_union;
Can somebody please tell me that what is the problem in the above
casting mechanism?
PS This is not an assignment. I took this code from the following
link:
http://paul.rutgers.edu/~rhoads/Code/cast_anything.c
to any other thing:
#define CAST(new_type,old_object) (*((new_type *)&old_object))
union
{
char ch[4];
int i[2];
} my_union;
long longvar;
longvar = (long)my_union; Illegal cast
//////////////// ILLEGAL
longvar = CAST(long, my_union); Legal cast
I understands that why the CAST macro works but I cannot understands
that what is the problem in the following casting :
longvar = (long)my_union;
Can somebody please tell me that what is the problem in the above
casting mechanism?
PS This is not an assignment. I took this code from the following
link:
http://paul.rutgers.edu/~rhoads/Code/cast_anything.c