In article <news:40******@news.rivernet.com.au>
Peter Nilsson <ai***@acay.com.au> writes:
jmp_buf is an array, not a struct.
Indeed. It may, of course, be a type-alias for an array of one
element, whose element-type is a structure type. This is the case
for every setjmp() implementation I have written (which is not
very many; mostly I have to work within someone else's initial
implementation).
In other words:
typedef struct __jmp_buf jmp_buf[1];
struct __jmp_buf { ... contents ... };
is a valid implementation, but changing the first line to:
typedef struct __jmp_buf jmp_buf;
is not, even if the implementation happens to pass structures by
reference internally. Why? Becuase the C Standards say so:
7.10 Nonlocal jumps <setjmp.h>
[#1] The header <setjmp.h> defines the macro setjmp, and
declares one function and one type, for bypassing the normal
function call and return discipline.191
[#2] The type declared is
jmp_buf
which is an array type suitable for holding the information
needed to restore a calling environment. ...
The C standard says "this is an array type" so it had better be an
array type. An implementation can cheat if and only if the effect
of cheating is invisible, and array types have visible characteristics.
For instance, "sizeof instance" is usually different from "sizeof
(instance + 0)", and applying "+ 0" to an array object is always
valid:
#include <setjmp.h>
#include <stdio.h>
int main(void) {
jmp_buf x;
printf("sizes: %lu %lu\n", (unsigned long)sizeof x,
(unsigned long) sizeof(x + 0));
return 0;
}
This *must* compile and will virtually always print two different
numbers (in rare cases you might actually get "8 8" today). The
array object "x" has as its size the number of bytes in the entire
array, while adding zero causes the array object to undergo the
transition prescribed by The Rule about arrays and pointers in C,
so that sizeof (x + 0) is the number of bytes in a pointer to the
first element of the array. The second number is usually 4 or 8
today, while the first is often at least 12 and almost always at
least 8 (to hold stack and frame pointers, plus another 4 or more
for signal information in POSIX systems).
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it
http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.