What is setjmp... Clarification and typedef gripe
Brandon Allbery
bsa at ncoast.UUCP
Fri Oct 5 03:57:47 AEST 1984
> Article <>
> From: nazgul at apollo.uucp (Kee Hinckley)
> Gary Moss <decvax!ucbvax!moss at Brl-Vld.ARPA> quite rightly pointed
> out that one ... should instead use the typedef "jmp_buf" sitting in:
>
> /usr/include/setjmp.h
>
> 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?
Yup. I think you may have found a compiler bug. Here on our humble
Xenix machine, I get:
-----------------------------------------
% cat jb.c
#include <setjmp.h>
main() {jmp_buf foo, *tmp; tmp = &foo;}
% cc jb.c -o foobar # a.out is in use
"jb.c", line 2: warning: & before array or function: ignored
"jb.c", line 2: warning: illegal pointer combination, op =
%
-----------------------------------------
Typedef can't help it -- as long as jmp_buf is an array, you get this.
Either we find a way to make it a struct, or we put up with it. But
why doesn't your compiler report the *real* problem? (Or is it one?)
--bsa
More information about the Comp.lang.c
mailing list