Path: utzoo!attcan!uunet!aplcen!samsung!cs.utexas.edu!usc!apple!sun-barr!newstop!sun!atticus!gds From: gds@atticus.Sun.COM (Greg Schechter) Newsgroups: comp.lang.c Subject: Portability of TypeCasting LHS's in C Keywords: LHS, typecast Message-ID: <130175@sun.Eng.Sun.COM> Date: 12 Jan 90 18:21:02 GMT Sender: news@sun.Eng.Sun.COM Reply-To: gds@sun.UUCP (Greg Schechter) Organization: Sun Microsystems - Graphics Standards Group - Mountain View, CA Lines: 47 Does anyone know the validity of typecasting an LHS in C. For example, I have the following: char *ptr; ((long *)ptr)++; That is, ptr is a pointer to a 1 byte entity and I want to increment that pointer by the sizeof(long), so typecasting it to a (long *) and incrementing it does work on those compilers that can handle such a beast. My question is: Is this portable C, K&R C, ANSI C, or none of the above?? Please respond directly to gds@Sun.COM. Below is a program which demonstrates this: ------------ #include main() { char *begin = (char *)malloc(40); char *end = begin + 40; char *charptr; int i; /* count through 40 bytes one char at a time */ for (i = 0, charptr = begin; charptr < end; charptr++, i++) printf("%d\t0x%x\n", i, charptr); /* count through 40 bytes one long at a time */ for (i = 0, charptr = begin; charptr < end; ((long *)charptr)++, i++) printf("%d\t0x%x\n", i, charptr); } ----------------- Thanks in advance, Greg Schechter Graphics Standards Software Sun Microsystems