strong/weak typing and pointers
Alex Martelli
aleaxit at yahoo.com
Fri Nov 5 01:40:24 EST 2004
Greg Ewing <greg at cosc.canterbury.ac.nz> wrote:
> Diez B. Roggisch wrote:
> > I can remeber abusing 32bit pointers in 68k processors by
> > altering the most-significant byte.
>
> Apple did this in early versions of the Memory Manager
> of classic MacOS, using the upper 8 bits of a Handle
> for various flags. You weren't supposed to make any
> assumptions about what the upper byte contained, but
> of course some people did... and their applications
> broke when 32-bit addressing came in...
I believe many implementations of high-level languages on machines where
addresses had to be aligned used LOW bits similarly. Say addresses of
integers need to be even or else a bus error will occur. Then, a word
that is used to hold an integer address has its low bit 'available' as a
flag -- it needs to be cleared before it's dereferenced, anyway.
This seems reasonably sound because, even if a later model of the CPU
should be extended to allow misaligned addresses, the OS need not
support that. Misaligned addresses can pay substantial performance
prices for little gain -- not sure about the state of play these days,
but just a few years ago you could boost the performance of some C codes
on intel CPUs (which always allowed address misalignment) quite a bit by
recompiling with flags telling the compiler to ensure addess alignment.
So, the low bit, when set, could indicate we're pointing to a Bignum
(like a Python long), when clear, that we're pointing to an ordinary
small integer, for example -- or other such dychotomous distinctions.
Of course, such an address-plus-flag must be handled as a bitmask (to
examine and clear the flag) or a pointer, interchangeably.
Alex
More information about the Python-list
mailing list