c programming style - READ THIS

mer at prism.UUCP mer at prism.UUCP
Thu Aug 29 05:12:00 AEST 1985


Since 'p+n', where p is a pointer and n is an integer, is equivalent to
adding n*sizeof(whatever p points to), the safe and portable way of adding
an integer to a pointer treated as an integer is 
	 (char *)p + n
since (I think) character are always a byte wide.  If that's not always the
case, I apologize; on the other hand, it's probably safe than converting
a pointer to an int or a long;  I had trouble porting something from a VAX
to a Pyramid because of a cast of this sort.



More information about the Comp.lang.c mailing list