[m-dev.] for review: concurrency primitives

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Sep 5 00:35:13 AEDT 2000


On 31-Aug-2000, Peter Ross <peter.ross at miscrit.be> wrote:
> On Thu, Aug 31, 2000 at 09:48:09PM +1100, Fergus Henderson wrote:
> > On 31-Aug-2000, Peter Ross <peter.ross at miscrit.be> wrote:
> > > +++ spawn.m	2000/08/31 07:45:57
> > > +	ME_create_thread((void *(*)(void *)) call_back_to_mercury_cc_multi,
> > > +			(void *) Goal);
> > 
> > Those casts look a bit sus. to me; why are they needed?
> > 
> 
> They avoid the warnings:
> spawn.m:66: warning: passing arg 1 of `ME_create_thread' from incompatible pointer type
> spawn.m:66: warning: passing arg 2 of `ME_create_thread' makes pointer from integer without a cast

Well, they do suppress the warnings, but I think they don't solve the
problem, at least not in a maximally portable way...
more like sweep it under the carpet ;-)

In general, casting function pointers to different types --
except when you do it just for the purpose of later casting back
to the same function pointer type -- is not standard-conforming,
and at least in theory is not portable, since implementations might
use different calling conventions for different function pointer
types.  For example, on the m68000, a `void *' parameter might get
passed in an address register, e.g. a0, whereas an `MR_Word' parameter
might get passed in a data register, e.g. d0.

The right way to do this is to write a wrapper function that has
the correct type, and to pass the address of the wrapper function.
Then you put the casts inside the wrapper function, rather than
casting a function pointer.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list