Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!think!ames!amdahl!amdcad!nucleus!tim From: tim@nucleus.amd.com (Tim Olson) Newsgroups: comp.os.minix Subject: Re: Zen and the Art of Library Programming Message-ID: <28591@amdcad.AMD.COM> Date: 3 Jan 90 15:23:27 GMT References: <7259@nigel.udel.EDU> <22702@princeton.Princeton.EDU> Sender: news@amdcad.AMD.COM Reply-To: tim@amd.com (Tim Olson) Organization: Advanced Micro Devices, Inc., Austin, Texas Lines: 57 Summary: Expires: Sender: Followup-To: In article <22702@princeton.Princeton.EDU> nfs@notecnirp.UUCP (Norbert Schlenker) writes: | In article <7259@nigel.udel.EDU> Leisner.Henr@xerox.com (marty) writes: | >Norbert Schlenker says: {{ | > | > | >---------------------------------------------------------------------------- | >#include | >#include | > | >abort() | >{ | > while (1) | > fprintf(stderr, "Stupid jerk!\n"); | >} | > | >main() | >{ | > assert(0==1); | >} | > | >---------------------------------------------------------------------------- | > | >This is a valid ANSI C program which should terminate with a SIGABRT | >signal. No, it isn't valid. | >Instead, the linker will use the program's definition of abort(), and this | >program will go into an infinite loop when run. (Just as an aside, this is | >a useful test program for many compilers that claim ANSI compatibility.) This is legal, since the operation of the program is undefined. | >What is the compiler supposed to do with the program? Generate a warning? | >Generate a fatal error? Its valid C code. Why should the compiler (for | >the language) know anything about the library functions (this ain't PL/1). | | The compiler should compile the program without error or warning, because | the program has no errors in it. Yes, it does have an error (see below): | The point is that the assert() macro has | a guaranteed effect (according to ANSI), and the last part of that effect | is to terminate the program by calling the abort() function. The abort() | function cited by ANSI is that of the ANSI standard, not a programmer | supplied one (i.e. ANSI expects the program to die after assert(0==1)). | A C compiler/library/linker combination that can't do this is BROKEN. This is not correct. The program is erroneous because it defines an identifier with the same name as an identifier that is reserved (namely abort). The behavior of the program is undefined. See Section 4.1.2.1 (Reserved Identifiers). -- Tim Olson Advanced Micro Devices (tim@amd.com)