Mail Archives: djgpp/1998/07/29/10:29:54
Hi, All!
29.07.98, nikki AT kki DOT net DOT p wrote:
> During writing a function I noticed that operations - such as addition
> or substraction - on pointers of different types than char didn't
> behave as I expected them to. Eg. adding 2 to the the pointer :
> short *pointer_to_short ;
> resulted in 4 byte offset,not 2 byte. Same for ints etc.
> So the question is : is it really a fact,that gcc's pointer math
> depends on type rather than raw bytes ?
It is not an gcc feature or specific behaviour, it is standard C
behaviour. When you have a variable foo:
char *foo;
then
foo++ points to the next byte,
((int*)foo)++ points to the next int (+4 bytes in 32-bit program),
((double*)foo)++ points to the next double (+8 bytes I think).
Regards,
Alexander Bokovoy, <bokovoy AT bspu DOT unibel DOT by>
--=== The Soft Age coming soon ===--
- Raw text -