Another silly question

Roger Critchlow rec at elf115.uu.net
Fri May 26 08:26:40 AEST 1989



In <105998 at sun.Eng.Sun.COM>
jamesa at arabian.Sun.COM (James D. Allen) had written:
>                                         But a logical array can be
>promoted to a first-class citizen by just putting it in a structure:
>
>		typedef struct {
>			jmp_buf j;
>		} first_class_jmpbuf;
>
>Any idea why this wasn't done for jmp_buf's?

In <13269 at haddock.ima.isc.com>
karl at haddock.ima.isc.com (Karl Heuer) responded:
>In article <105998 at sun.Eng.Sun.COM> jamesa at arabian.Sun.COM (James D. Allen) writes:
>>Any idea why this wasn't done for jmp_buf's?
>Originally?  Probably shortsightedness.  In ANSI C?  Backward compatibility.

I believe that struct's were still second class objects when
jmp_buf was first declared.

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().  It's also a useful trick
to remember if you want user declared data objects to be passed
to your library routines by reference.

In <105998 at sun.Eng.Sun.COM>
jamesa at arabian.Sun.COM (James D. Allen) continued:
>I think the "second-classedness" of arrays helps give C its elegant
>syntax.  Any other examples of the "problems" it causes?

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 *";

I reason 'const' because the value of the pointer cannot be changed,
and 'register' because the address of the pointer cannot be taken.

-- rec at elf115.uu.net --



More information about the Comp.lang.c mailing list