Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site rtp47.UUCP Path: utzoo!watmath!clyde!burl!ulysses!gamma!epsilon!zeta!sabre!petrus!bellcore!decvax!mcnc!rti-sel!rtp47!meissner From: meissner@rtp47.UUCP (Michael Meissner) Newsgroups: net.lang.c Subject: Re: Re: c programming style - READ THIS Message-ID: <167@rtp47.UUCP> Date: Sun, 1-Sep-85 11:15:34 EDT Article-I.D.: rtp47.167 Posted: Sun Sep 1 11:15:34 1985 Date-Received: Thu, 5-Sep-85 06:42:06 EDT References: <90@rtp47.UUCP> <5400011@prism.UUCP> Reply-To: meissner@rtp47.UUCP (Michael Meissner) Distribution: net Organization: Data General, RTP, NC Lines: 24 In article <5400011@prism.UUCP> mer@prism.UUCP writes: > >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. > This will break down on machines which are bit or word oriented, rather than byte oriented. The real question is why do you need to do this in the first place? (for word oriented machines, char pointers are typically bigger than word pointers, and truncatation occurs when converting from un-aligned character pointers back to word pointers; the addition typically would create an un-aligned character pointer) (for bit oriented machines, adding n to a pointer would actually add 8*n) Michael Meissner Data General