When is a cast not a cast?

Tim_CDC_Roberts at cup.portal.com Tim_CDC_Roberts at cup.portal.com
Sat May 20 07:59:13 AEST 1989


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 at cup.portal.com                | Control Data...
...!sun!portal!cup.portal.com!tim_cdc_roberts |   ...or it will control you.



More information about the Comp.lang.c mailing list