Hi
What is the C equivalent for reinterpret_cast?
Thanks
Hi
What is the C equivalent for reinterpret_cast?
Thanks
C-style casts just look like type names in parenthesis:
void *p = NULL;
int i = (int)p; // now i is most likely 0
Obviously there are better uses for casts than this, but that's the basic syntax.
A c-style cast:
int* two = ...;
pointerToOne* one = (pointerToOne*)two;
You can freely cast pointer types in C as you would any other type.
To be complete:
void *foo;
some_custom_t *bar;
other_custom_t *baz;
/* Initialization... */
foo = (void *)bar;
bar = (some_custom_t *)baz;
baz = (other_custom_t *)foo;
int *foo;
float *bar;
// c++ style:
foo = reinterpret_cast< int * >(bar);
// c style:
foo = (int *)(bar);