Another silly question

Karl Heuer karl at haddock.ima.isc.com
Fri May 26 13:40:21 AEST 1989


In article <96 at elf115.uu.net> rec at elf115.uu.net (Roger Critchlow) writes:
>In <13269 at haddock.ima.isc.com> karl at haddock.ima.isc.com (Karl Heuer) writes:
>>In article <105998 at sun.Eng.Sun.COM> jamesa at arabian.Sun.COM (James D. Allen) writes:
>>>Any idea why this [enclosing in a struct] wasn't done for jmp_buf's?
>>
>>Originally?  Probably shortsightedness.
>
>I believe that struct's were still second class objects when
>jmp_buf was first declared.

But arrays were (and still are) third-class objects.  A struct would still
have been the better choice.

(Or do you mean to suggest that structs didn't exist at all?  I bet if you go
back that far, typedef didn't exist either.)

>The declaration of a jmp_buf as an array means that the jmp_buf
>is passed by reference instead of by value.  This is essential
>to many implementations of setjmp().

Of course it has to be passed by reference; the function needs to write in it,
after all.  But what *should* have been done was to typedef jmp_buf as a
struct, and use "&" explicitly.  That's what the rest of the library uses when
call by reference is required.

>I think of C arrays as syntactic sugar for initialized pointers.  Thus
>	char foo[] = "I am an anonymous char *";
>is an abbreviation for
>	register char *const foo = "I am an anonymous char *";

This is very wrong, but I'll let Chris Torek explain why, since he already has
it in his FAQ database.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list