[MLton] Port to HP-UX

Ville Laurikari ville@laurikari.net
Tue, 25 Apr 2006 19:18:17 +0300

On Mon, Apr 24, 2006 at 02:47:27PM -0700, Stephen Weeks wrote:
> The offending four fields of s, which is of type GC_state, are all of
> type GC_thread, declared in gc.h with a typedef:
>   typedef struct GC_thread {
>   ... struct fields omitted ...
>   } *GC_thread;
> So, it looks like we're relying on the fact that a pointer to a
> GC_thread can be treated as a pointer to a "pointer", where "pointer"
> is a typedef for char*.  I don't know of a better way in C to code

After some googling I found a working (although a bit ugly) solution.
C99 explicitly allows type-punning using unions, so declaring

        union { 
                GC_thread *t;
                pointer *p;
        } u;

and then converting the pointers using the union

        u.t = &s->callFromCHandler;
        maybeCall (f, s, u.p);
        u.t = &s->currentThread;
        maybeCall (f, s, u.p);
        u.t = &s->savedThread;
        maybeCall (f, s, u.p);
        u.t = &s->signalHandler;
        maybeCall (f, s, u.p);

avoids the warnings.  The same trick could probably be applied to the
other places where we currently just ignore the C99 violation using