[mercury-users] Debugging Mercury Programs
Fergus Henderson
fjh at cs.mu.oz.au
Wed Oct 22 05:04:07 AEST 1997
Ralph Becket wrote:
> > :- pred trc_msg(string).
> > :- mode trc_msg(in) is semidet.
> >
> > :- pragma c_code(
> > trc_msg(Msg::in),
> > may_call_mercury,
> > "{
> > printf("\ntrc_msg: %s\n", Msg);
> > }").
>
> Just to clarify: the semidet declaration is there to prevent the
> compiler from optimising away calls to trc_msg/1.
First, a minor nit: if the procedure is semidet, you need to include
`SUCCESS_INDICATOR = TRUE;' after the printf().
But I'm afraid that declaring the procedure `semidet' is neither necessary
nor sufficient for that purpose.
It is not sufficient because the compiler may optimize multiple calls
to trc_msg/1 with the same message into a single such call.
You need to use the `--no-optimize-duplicate-calls' option to prevent this.
It is not necessary because by default, apart from optimizing away duplicate
calls, the compiler won't optimize calls to trc_msg/1 away even if it is det.
(To get it to optimize away such calls, you would need to specify
`--no-fully-strict'.).
--
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.
More information about the users
mailing list