Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!wuarchive!udel!mmdf From: Leisner.Henr@xerox.com (marty) Newsgroups: comp.os.minix Subject: Re: Zen and the Art of Library Programming Message-ID: <7259@nigel.udel.EDU> Date: 3 Jan 90 02:08:46 GMT Sender: mmdf@udel.EDU Lines: 60 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. 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.) }} 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). I quickly glanced through the May, 88 dpans and found nothing to confirm or deny it. Anyone have a reference? While having no proof one way or another, I maintain redefining library functions is within the spirit of C. I often do it since the library version doesn't do what I want or has problems or whatever. Recompiling the source code with magic macros to use different functions (i.e. cc -Dabort=myabort) is insufficient -- what if I want to library functions to use my version ? A common mistake by beginning C programmers is to use library functions names for their own functions and then watch the chaos that follows (read and write are good examples, especially when the program does STDIO) . Part of the spirit of C I enjoy so much is the assumption the programmer knows what he's doing (maybe he wants to redefine write() -- i.e. perhaps do some special profiling and then generate the syscall). One more note: Does the Minix compiling system properly understand public/private? I understood at one time static really didn't do anything regarding name-space pollution. marty ARPA: leisner.henr@xerox.com GV: leisner.henr NS: leisner:wbst139:xerox UUCP: hplabs!arisia!leisner