Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site polyof.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!bbnccv!bbncca!linus!philabs!ron1!polyof!john From: john@polyof.UUCP ( John Buck ) Newsgroups: net.lang.c Subject: how has C bitten you Message-ID: <150@polyof.UUCP> Date: Tue, 3-Sep-85 00:22:26 EDT Article-I.D.: polyof.150 Posted: Tue Sep 3 00:22:26 1985 Date-Received: Thu, 5-Sep-85 08:27:01 EDT Distribution: net Organization: Polytechnic Inst. of NY, Farmingdale Lines: 42 This may have been mentioned before, but for those who have not had the experience of tracking down this "bug", here it is again: ----------- Code follows here ---------- #define recip(x) (1.0/x) main() { double *p, d; d = 7.0; p = &d; d = recip(*p); printf("%f %f\n", d, *p); } ---------End of Code --------- From this, I have learned: #define recip(x) (1.0/(x)) However, there is still no guarding against: d = 1.0/*p; except, d = 1.0 / *p; or d = 1.0/(*p); but often, you do not realize your mistake until you decipher the exceedingly inaccurate messages of all C compilers we have. Sys5 pcc, Sys5 cc (Ritchie compiler, 11/70), Berkeley 4.2, lint. They all say pretty much the same thing: syntax error on line N Where N = number of lines in program + 1 (IE a non-existant line) or, if you are lucky, the first line after the next comment in your program. John Buck Polytechnic Inst. of NY Route 110 Farmingdale, NY 11735 (decvax!philabs!ron1!polyof!john or decvax!mcnc!rti-sel!polyof!john)