Keith Thompson <kst-u@mib.orgwrites:
Quote:
CJ <nospam@nospam.invalidwrites:
Quote:
>It seems to be quite common in libraries (e.g. GMP) to have typedefs
>like
>>
>typedef struct {
> /* stuff */
>} __type_struct;
>typedef __type_struct type_t[1];
>>
>I guess the advantage of this is that it allows type_t variables to be
>passed by reference without an extra level of indirection.
>>
>Is this considered good C style? Are there any problems or pitfalls to
>be wary of with this approach?
>
I'm sure it's considered good C style by some people. [...]
....including at least some members of the standards committee, I
guess, since that's jmp_buf is required to be declared:
7.13 Nonlocal jumps <setjmp.h>
1 The header <setjmp.hdefines the macro setjmp, and declares
one function and one type, for bypassing the normal function
call and return discipline.207)
2 The type declared is
jmp_buf
which is an array type suitable for holding the information
needed to restore a calling environment.
The Rationale adds:
7.13 Nonlocal jumps <setjmp.h>
jmp_buf must be an array type for compatibility with
existing practice: programs typically omit the address
operator before a jmp_buf argument, even though a pointer
10 to the argument is desired, not the value of the
argument itself. Thus, a scalar or structure type is
unsuitable. Note that a one- element array of the
appropriate type is a valid definition.
--
"For those who want to translate C to Pascal, it may be that a lobotomy
serves your needs better." --M. Ambuhl
"Here are the steps to create a C-to-Turbo-Pascal translator..." --H. Schildt