c - Pointer/address type casting -
i have following variables:
char *p; int l=65;
why following casts fail?
(int *)p=&l;
and:
p=&((char) l);
the result of type conversion rvalue. rvalue cannot assigned to, why first expression doesn't compile. rvalue cannot taken address of, why second expression doesn't compile.
in order perform correct type conversion, have to follows
p = (char *) &l;
this proper way tried in second expression. converts int *
pointer char *
type.
your first expression beyond repair. can do
*(int **) &p = &l;
but in end not conversion, rather reinterpretation of memory occupied char *
pointer int *
pointer. ugly illegal hack of time has little practical value.
Comments
Post a Comment