What is setjmp... Clarification and typedef gripe

Kee Hinckley nazgul at apollo.uucp
Tue Oct 2 04:39:17 AEST 1984


...
Gary Moss <decvax!ucbvax!moss at Brl-Vld.ARPA> quite rightly pointed
out that one should never declare the jump buffer as being some
explicit size, but should instead use the typedef "jmp_buf" sitting in:

            /usr/include/setjmp.h

This way you'll avoid the machine dependance problem.

I agree with this whole-heartedly, the only thing that bugs me is
the way typedef works, which is essentially as a #define.  For
example:
-----------------------------------------------------------------------
#include <stdio.h>
#include <setjmp.h>

main()
{
    jmp_buf foo, *tmp;

    tmp = &foo;
}
$ cc foo

 (0008)     tmp = &foo;
******** Line 8: Warning:  Illegal pointer combination: incompatible types.
No errors, 1 warning, C Compiler, Rev 2.40
-------------------------------------------------------------------------
The error message may differ on your machine, but most compilers do at
least give some warning.  The way around it:
            tmp = (jmp_buf *) &foo;
works, but is rather frustrating.

The whole point of a typedef (in my mind at least) is to create a
level of abstraction that alleviates the need to learn what the machine/
compiler architecture actually looks like.  To a certain degree typedef
seems to succeed at this, but then it all falls apart.  Any thoughts?

                                            -kee



More information about the Comp.lang.c mailing list