Mail Archives: djgpp/1998/07/29/15:42:53
Inquisitor Nikodemus wrote in message
<35bf1ff4 DOT 1246159 AT news DOT icm DOT edu DOT pl>...
|Hey!
|
|
|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 really a fact that all legal C implementation do pointer
arithmetic with regard to type. That is why pointer arithmetic on void
* is undefined in standard C (gcc has a loophole here): there is no size
associated with void.
Since E1[E2] means the same thing as *(E1+(E2)), this in an inescapable
fact of life in C.
Your question is about C rather than about gcc. If you have more
questions about C, the right newsgroup is news://comp.lang.c
Martin Ambuhl (mambuhl AT tiac DOT net)
/* Newsgroup posts also e-mailed */
|
|
|/greetz
|Nikki
- Raw text -