[m-dev.] ODBC interface
Fergus Henderson
fjh at cs.mu.oz.au
Wed Jul 23 23:20:42 AEST 1997
Simon TAYLOR, you wrote:
> + /*
> + ** MR_setjmp(MR_jmp_buf *env)
> + **
> + ** Save MR_engine_jmp_buf, then call setjmp(env).
> + ** setjmp can only occur as an expression, not a statement.
> + ** I'm not certain that this is 100% portable. K&R p254 states
> + ** that "a call to setjmp can only occur in certain contexts,
> + ** basically the test of if, switch and loops, and only in
> + ** simple relational expressions". Is the expression below
> + ** a simple relational expression?
> + */
> +#define MR_setjmp(setjmp_env) \
> + ( \
> + (setjmp_env)->mercury_env = MR_engine_jmp_buf, \
> + setjmp((setjmp_env)->env) \
> + )
No, it will not be simple relational expression.
if (MR_setjmp(setjmp_env)) {
exands to
if (( (setjmp_env)->mercury_env = MR_engine_jmp_buf,
setjmp((setjmp_env)->env) )) {
which is not conforming ANSI C.
Instead it needs to be something like
setjmp_env->mercury_env = MR_engine_jmp_buf;
if (setjmp(setjmp_env->env)) {
Instead, I suggest you use either
#define MR_pre_setjmp(setjmp_env) \
((setjmp_env)->mercury_env = MR_engine_jmp_buf)
#define MR_setjmp(setjmp_env) \
setjmp((setjmp_env)->env)
with
...
MR_pre_setjmp(setjmp_env);
if (MR_setjmp(setjmp_env)) {
...
}
...
or
#define MR_setjmp(setjmp_env, longjmp_label, fallthru_label) \
do { \
(setjmp_env)->mercury_env = MR_engine_jmp_buf; \
if (setjmp((setjmp_env)->env)) \
goto longjmp_label; \
else \
goto fallthru_label; \
} while(0)
with
...
MR_setjmp(setjmp_env, longjmp_label, fallthru_label);
longjmp_label:
...
fallthru_label:
...
--
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 developers
mailing list