Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!cmcl2!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: Efficient coding considered harmful? Message-ID: <8865@smoke.BRL.MIL> Date: 12 Nov 88 04:47:26 GMT References: <3105@hubcap.UUCP> <34112@XAIT.XEROX.COM> <1700@dataio.Data-IO.COM> <7700@bloom-beacon.MIT.EDU> <771@wsccs.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 59 In article <771@wsccs.UUCP> dharvey@wsccs.UUCP (David Harvey) writes: >... who would fail me for the following code: >if( ! something) { > ++j; >but would pass me with flying colors for the following: >if ( something != 0) > { > j = j + 1; If "something" is conceptually Boolean, then even your instructor should think !something is preferable to something==0 (note the bug fix) since his favorite languages have explicit Boolean NOT operators. On the other hand, if "something" is conceptually arithmetic, then something==0 is stylistically preferable to !something. ++ is obviously thought of as a unary increment operator, which those other langauges don't have (which is probably why your instructor is not comfortable with the idea). >declaration of variables within the function parentheses will >provide the 'protection' that Pascal lovers want only if the >compiler can compile both the caller and callee at the same time. >Or the linker must be more sophisticated, using information that >is generated by the compiler. How will it be handled folks? I see you don't understand how function prototypes work. (Perhaps this is due to your instructors also?) The compiler can (indeed, must) check function arguments and parameters against the corresponding prototype when it is in scope. Typically this occurs when a prototype declaration is supplied in an "interface" header file that is #included near the beginning of each source file that refers to things defined or declared by that header. >But then we could always #include C code files, which is exactly >what one of the afore-mentioned teachers required of beginning C >students! Obviously he has a Pascal mind-set. One of C's important features is the support for separate compilation. ANSI C's function prototypes in no way weaken this; in fact they better support it. No linker support is required beyond that required by "K&R C". ----- My advice to you as a student is to learn proper C usage from books by people like Brian Kernighan and Tom Plum. (There are other good authors of C books too, as well as scores of bad ones. I just picked a couple of the best.) Give your instructors whatever silly crap they demand and don't waste time worrying about it or trying to educate your instructors. School serves two main practical purposes: it gets you a scrap of sheepskin that helps you get a desirable job, and it potentially helps you learn how to learn under your own steam. The actual data content of your courses won't usually do you much good later in life, but general methods of gathering and evaluating information remain valid "forever".