strong/weak typing and pointers

Alex Martelli aleaxit at yahoo.com
Thu Nov 4 21:54:31 CET 2004


Steven Bethard <steven.bethard at gmail.com> wrote:
   ...
> I'm obviously upsetting you, and I can see that we're still not quite
> understanding each other.  I have to assume that you're not the only one I'm
> upsetting through these misunderstandings, so for the sake of the list, I'll
> stop responding to this thread.  Thanks everyone for a good discussion!

I apologize if I have given the impression of being upset.  I am, in a
way, I guess -- astonished and nonplusses, as if somebody asked me to
justify the existence of bread -- not of some exotic food, mind you, but
of the most obvious, elementary, fundamental substance of earthly
sustenance (in my culture, and many others around it).

> P.S. If anyone would like to know my response to the float representation
> example, please contact me directly instead.

I promise not to ACT upset if you explain it here.  So, we have an area
of 8 bytes in memory which we need to be able to treat as:
    8 bytes, for I/O purposes, say;
    a float, to feed it to some specialized register, say;
    a bit indicating sign plus 15 for mantissa plus 48 for significand,
        or the like, to perform masking and shifting thereof in SW -- a
        structure of three odd-bit-sized integers juxtaposed;
and this is ONE example -- the specific one you had asked for.

Another example: we're going to send a controlblock of 64 bytes to some
HW peripheral, and get it back perhaps with some mods -- a typical
control/status arrangement.  Depending on the top 2 (or in some case 4)
bytes' value, the structure may need to be interpreted in several
possible ways, in terms of juxtaposition of characters, halfwords and
longwords.  Again, the driver responsible for talking with this
peripheral needs to be able to superimpose on the 64 bytes any of
several possible C-level struct's -- the cleanest way to do this would
appear to be pointer-casting, though unions would (as usual, of course)
be essentially equivalent.  In Python, or another language that lets me
pack and unpack a struct to/from bytes in a controlled way (in Python's
case via the struct module) I can do that through a _copy_ -- I need to
go through a 'raw bytes' stage, cannot do the overlay directly; but
that's little more than a figleaf arrangement -- spending real CPU and
RAM operations because I can't be lowlevel/weakly-typed enough.


Alex



More information about the Python-list mailing list