Portable uses of jmpbuf's

John Sambrook john at uw-nsr.UUCP
Sat Oct 15 14:45:58 AEST 1988


In article <4700023 at m.cs.uiuc.edu> wsmith at m.cs.uiuc.edu writes:
>
>>/* ---------- "Portable uses of jmpbuf's" ---------- */
>>How do you portably pass a jmpbuf as a parameter to a C function?
>>
>>Some machines define a jmpbuf to be struct { stuff } , while
>>others define a jmpbuf to be an array.  In one case, an & is required, 
>>while in the other case it is not.
>>
>>My best solution was to define my own structure with one field of a 
>>jmpbuf and then always take the address.
>>
>>Is there a better way?
>
>Here is a more detailed description of the problem:
>
>If I have a function that I want to pass the address of a jmpbuf to it,
>with "typedef struct {} jmpbuf;", the call to the function will be
>"function(&a_jmpbuf);" and the prototype ala Microsoft C will be 
>"function( jmpbuf * a );"
>
>With "typedef int jmpbuf[10];", the call to the function will be
>"function(a_jmpbuf);" and the prototype will be "function( jmpbuf a );"
>because the array gets converted into a pointer to its first element when
>I make the call.  If I try to make the prototype "function( jmpbuf * a) ;",
>the call will no longer match even if make the call be the same as with
>the struct version of jmpbuf.
>
>I have heard that one fix is to wait for an ANSI compatible compiler which
>will allow "function(&a_jmpbuf);" and "function(jmpbuf * a);" in either case.
>
>Bill Smith	uiucdcs!wsmith		wsmith at cs.uiuc.edu
>

It seems to me that the problem is how to (reliably, portably) take the
address of a jmp_buf.  The prototype for the called function should
always be "function(jmp_buf *a);"

How about the following?

#if JMP_BUFS_ARE_STRUCTS
#define JMP_BUF_ADDR(X)		(&X)
#else
#define JMP_BUF_ADDR(X)		(X)
#endif

Obviously, you would use this code like this:

	function(JMP_BUF_ADDR(my_jmp_buf));

Granted, you have to figure out the truth of JMP_BUFS_ARE_STRUCTS for
each machine, but that may be better than trying to come up with some
"unification" scheme. 


-- 
John Sambrook                        Internet: john at nsr.bioeng.washington.edu
University of Washington RC-05           UUCP: uw-nsr!john
Seattle, Washington  98195               Dial: (206) 548-4386



More information about the Comp.lang.c mailing list