Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!elf115!rec From: rec@elf115.uu.net (Roger Critchlow) Newsgroups: comp.lang.c Subject: Re: Another silly question Summary: jmp_buf is passed by reference Message-ID: <96@elf115.uu.net> Date: 25 May 89 22:26:40 GMT References: <17812@cup.portal.com> <607@kl-cs.UUCP> <749@mccc.UUCP> <13269@haddock.ima.isc.com> Organization: ELF, Sea Cliff, NY Lines: 46 In <105998@sun.Eng.Sun.COM> jamesa@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@haddock.ima.isc.com> karl@haddock.ima.isc.com (Karl Heuer) responded: >In article <105998@sun.Eng.Sun.COM> jamesa@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@sun.Eng.Sun.COM> jamesa@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@elf115.uu.net --