Re: XForms: Data casting to callbacks

Kaz Kylheku (kaz@cafe.net)
Fri, 11 Jul 1997 10:40:20 -0700 (PDT)

To subscribers of the xforms list from Kaz Kylheku <kaz@cafe.net> :

On Wed, 9 Jul 1997, Steve Lamont wrote:

> Date: Wed, 9 Jul 97 15:34:57 PDT
> From: Steve Lamont <spl@szechuan.ucsd.edu>
> Reply-To: xforms@bob.usuf2.usuhs.mil
> To: xforms@bob.usuf2.usuhs.mil
> Subject: Re: XForms: Data casting to callbacks
>
> To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :
>
> > > I suggest *not* casting your structure pointer to a long. Remember
> > > that on some machines longs and pointers are *not* the same length --
> > > on the DEC Alpha, pointers are 64 bits while a long is only 32 bits!

Someone was asking about this in comp.lang.c.moderated.

The answer is that the language makes no guarantees here. C permits an
integer to be converted to a pointer with an implementation-defined result.
It also allows a pointer to be converted to an integer, only if that integer
is sufficiently wide. If that is the case, the result is implementation
defined, otherwise undefined behavior results.

Nothing is said about the nature of the pointer to integer and integer to
pointer mapping functions, hence it cannot be assumed that they are mutual
inverses. In other words, even if the conversion succeeds in both directions
(i.e does not trigger undefined behavior) you might not get back the original
integer value.

Actually something is said about the mapping functions, but in a footnote
(footnotes are not part of the standard) and all the footnote says is that
the mapping functions are intended to be consistent with the addressing
structure of the execution environment.

There is no reason to perform such conversions in an ordinary program; the
purpose is to provide an ``escape hatch'' for low-level access to the
hardware. For example, if your environment provides a graphics frame buffer at
some fixed address, you can convert an integer value representing that address
to a pointer so that you can access the buffer. In some embedded applications,
it may sometimes be desirable to convert a pointer (e.g. stack pointer of a
process) to an integer. Most other uses can't be rationalized, because there
is usually a legal way to accomplish the desired operation. For example, if a
callback mechanism supports only a void * generic argument, then pass a
pointer to your integer instead of converting the integer itself to a pointer.

_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
Xforms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/