Path: utzoo!attcan!uunet!husc6!bloom-beacon!mit-eddie!uw-beaver!tikal!sigma!uw-nsr!john From: john@uw-nsr.UUCP (John Sambrook) Newsgroups: comp.lang.c Subject: Re: Portable uses of jmpbuf's Message-ID: <1402@uw-nsr.UUCP> Date: 15 Oct 88 04:45:58 GMT References: <4700022@m.cs.uiuc.edu> <4700023@m.cs.uiuc.edu> Reply-To: john@uw-nsr.UUCP (John Sambrook 548-4386) Organization: UW-Bioengineering, Seattle, WA Lines: 58 In article <4700023@m.cs.uiuc.edu> wsmith@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@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@nsr.bioeng.washington.edu University of Washington RC-05 UUCP: uw-nsr!john Seattle, Washington 98195 Dial: (206) 548-4386