Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!uwvax!dogie.macc.wisc.edu!csd4.milw.wisc.edu!lll-winken!uunet!portal!cup.portal.com!Tim_CDC_Roberts From: Tim_CDC_Roberts@cup.portal.com Newsgroups: comp.lang.c Subject: Re: When is a cast not a cast? Message-ID: <18559@cup.portal.com> Date: 19 May 89 21:59:13 GMT References: <2747@buengc.BU.EDU> <10191@smoke.BRL.MIL> <406@skye.ed.ac.uk> <10276@smoke.BRL.MIL> <2890@buengc.BU.EDU> <546@TSfR.UUCP> <2908@buengc.BU.EDU> Organization: The Portal System (TM) Lines: 27 The meaninglessness of pointer+pointer becomes more clear if you consider your typical relocating loader. If I have a module with a local symbol "x" at offset 100, and a local symbol "y" at offset 200, then the actual values of &x and &y at run time are actually (100+relocation_value) and (200+relocation_value). The operation &y-&x makes some sense, because (200+r.v.) - (100+r.v.) is simply the absolute value 100. However, &y + &x becomes 300 + 2 x (relocation value), and that doesn't make sense. &x is type pointer-to-something. &y is pointer-to-something. &y-&x is an integer. But &x+&y is...what? It doesn't point to anything so it can't be a pointer, and yet it's not an integer because it's value varies depending on the load address of the module. The COMPASS assembler for the CDC Cyber series addressed this problem. It allowed some quite complex expressions, but you had to watch your relocations. X CON 0 X is relocatable Y CON 0 Y is relocatable A1 SET X A1 is relocatable A2 SET Y-X A2 is absolute, and has the value "1". A3 SET X+3 A3 is relocatable A4 SET X+Y-X A4 is relocatable; this was allowed A5 SET X+Y ** ERROR: MULTIPLY RELOCATABLE SYMBOL ** Tim_CDC_Roberts@cup.portal.com | Control Data... ...!sun!portal!cup.portal.com!tim_cdc_roberts | ...or it will control you.