pointer question, a correction to prev posting

P McFerrin mcferrin at inuxc.UUCP
Fri Apr 6 06:22:22 AEST 1984


A pointer has a length associated with it.  The reason for this is that it
permits such operations as auto-increment/decrement.  If the pointer
is to a char, then an autoincrement operation would bump the pointer
value by 1.  On the other hand, the pointer was to 64 byte complex structure,
an autoincrement operation would increment the pointer value by 64.
The compiler takes care of the boundary allignment problems which will
result in the length of a pointer being adjusted to maintain proper
boundary allignment.

# It is dangerous to increment pointer yourself (e.g. p = p + 4).
# By doing so, you are restricting your programs to a specific machine type
# since wordsize varies among diffenent machines. (a act against portability)

The above statement (prefixed with #) is INCORRECT.  The C-compiler will
multiply the 4 by an appropiate scale (length of object being pointed to).
Many thanks to those who sent sent me mail regarding this matter.
(Ref: Page 94, C-Programming Language by Kernighan & Ritchie)

					Paul McFerrin
					AT&T Consumer Products
					...ihnp4!inuxc!mcferrin



More information about the Comp.lang.c mailing list