santosh <santosh.k83@gm ail.comwrites:
abhaybhat wrote:
>
>
Not portably. A pointer of type T* may hold either the value NULL or the
address of an object of type T. The special pointer void* may hold NULL
or the address of any object type, but may not be deferenced. Nor can
you do pointer arithmetic on void*.
>
>
That's how the language has been designed. The main reason is
implementabilit y on systems where different pointer types may be
incompatible with each other, i.e., their size may be different, their
representation may be different, etc.
>
>Hello all,
>>
>char a[2]
>char* u8
>int u32
>>
>u8 = &u32
>>
>Cant we referance a char pointer to int ?
>>
>char a[2]
>char* u8
>int u32
>>
>u8 = &u32
>>
>Cant we referance a char pointer to int ?
Not portably. A pointer of type T* may hold either the value NULL or the
address of an object of type T. The special pointer void* may hold NULL
or the address of any object type, but may not be deferenced. Nor can
you do pointer arithmetic on void*.
>
>Why is this not possible?
That's how the language has been designed. The main reason is
implementabilit y on systems where different pointer types may be
incompatible with each other, i.e., their size may be different, their
representation may be different, etc.
around assigning float values to int objects and so forth. (You can
still do such things, but it's a bit more complicated, and the
gyrations you have to go through make it a bit clearer that it's
non-portable.)
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Leave a comment: