c - Is size of char * same as size of int *? -
i know: char * pointer char. , int * pointer int.
so, want confirm next 2 things:
so suppose on 32 bit machine, means memory addresses 32 bit wide. means size of char * , int * both 32 bits ( 4 bytes), right ? size of char * * same size of int * ?
suppose have: int * ptr;
thus doing *((char * *) ptr) = 0x154 same *((int *) ptr) = 0x514 same, right ? ( 0x514 random memory address)
platform: on x86.
p.s.: know type casting not suggested way code. doing kernel coding, have type casting !
in c pointers not guaranteed have same size. in reality implementations pointers same size, implementation detail of compiler.
from c faq:
the old hp 3000 series uses different addressing scheme byte addresses word addresses; several of machines above hence uses different representations char * , void * pointers other pointers
depending on ``memory model'' in use, 8086-family processors (pc compatibles) may utilize 16-bit info pointers , 32-bit function pointers, or vice versa.
also *((char *)ptr) = 0x154
not same *((int *)ptr) = 0x154
. because dereferencing pointer write info size of char
, size of int
location pointed ptr
. assuming 8 bit char , 32 bit int, *((char *)ptr) = 0x154
write0x154
memory address assigned ptr
, *((int *)ptr) = 0x154
write 0x0000000154
4 bytes starting @ address assigned ptr
.
c pointers assembly dereference
No comments:
Post a Comment