pointers to arrays
Wayne Throop
throopw at dg_rtp.UUCP
Wed Nov 26 09:12:51 AEST 1986
Stuart coded an example that "ought to work" under X3J11 C like so:
> #include <setjmp.h>
> jmp_buf *envptr;
> void f(){
> jmp_buf local_env;
> envptr = &local_env;
> if (!setjmp(local_env)) {
> /* . . . */
> }
> }
Couple of points. A longjmp to the envptr, coded like so:
longjmp( envptr, 1 );
would be type incorrect, since envptr has type (jmp_buf *) (that is,
type (int (*)[N])), and longjmp expects type a promoted jmp_buf type
(that is, type (int *)). The longjmp ought to be coded:
longjmp( *envptr, 1 );
Note that Stuart wanted a "better way" to code all this under current,
pre X3J11 C. I note that if you don't mind the sleaziness of knowing
that jmp_buf is really an array, and what element type jmp_buf has (int,
in most cases), you can code it like so:
#include <setjmp.h>
int *envptr;
void f(){
jmp_buf local_env;
envptr = local_env;
if (!setjmp(local_env)) {
/* . . . */
}
}
And then, the longjmp becomes just
longjmp( envptr, 1 );
I hope everybody sees why this works.
--
A program without a loop and a structured variable isn't worth writing.
--- Alan J. Perlis
--
Wayne Throop <the-known-world>!mcnc!rti-sel!dg_rtp!throopw
More information about the Comp.lang.c
mailing list