Path: utzoo!attcan!uunet!mcvax!hp4nl!targon!ruud From: ruud@targon.UUCP (Ruud Harmsen) Newsgroups: comp.lang.c Subject: Re: "do ... while ((NULL + 1) - 1);" -- valid C? Message-ID: <597@targon.UUCP> Date: 16 Aug 89 13:06:57 GMT References: <1043@levels.sait.edu.au> <961@virtech.UUCP> <10684@smoke.BRL.MIL> <940@lakesys.UUCP> <18996@mimsy.UUCP> Reply-To: ruud@targon.UUCP (Ruud Harmsen) Organization: Nixdorf Computer BV., SWP, P.O. Box 29,Vianen, The Netherlands Lines: 20 In article <18996@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >Consider: If we write > char *cp; > int *ip; > ip = cp; > >the compiler must issue some kind of diagnostic (it says so in the >proposed ANSI C specification, and it says in K&R-1 that this operation >is machine-dependent, ... I suppose this is machine-dependent because of alignment: char-pointers can point to just about anywhere, but int-pointers on many machines have to be aligned properly. My question is: can I make sure in my program, that though generally non-portable this IS portable? I tried this once in the following way: The char-pointer gets its value from malloc, which the manual says gives pointers properly aligned for any type. I never change that char-pointer other than by adding multiples of sizeof(int) to it. Is a "ip = cp" guaranteed safe under these conditions, so can I ignore the compiler-warning?