Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site crystal.UUCP Path: utzoo!watmath!clyde!bonnie!akgua!whuxlm!harpo!decvax!linus!philabs!cmcl2!seismo!uwvax!crystal!shekita From: shekita@crystal.UUCP Newsgroups: net.lang.c Subject: more questions about efficient C code Message-ID: <474@crystal.UUCP> Date: Fri, 21-Jun-85 14:18:14 EDT Article-I.D.: crystal.474 Posted: Fri Jun 21 14:18:14 1985 Date-Received: Mon, 24-Jun-85 04:48:43 EDT Distribution: net Organization: U of Wisconsin CS Dept Lines: 35 I am currently modifying C code, written by someone else, that is incredibly terse. It's paramount that the code be fast, so I presume the code is terse for speed. I'm now curious about a few things: 1) Is the "var = (bool expr) ? : expr1 : expr2" construct faster than just a good old if statement? 2) Are for loops faster than while loops? 3) Is there really much to be gained by using assignment within a boolean expression, for example, is if ((fp = fopen("foo", "r") == NULL) { ... } really that much faster than fp = fopen("foo", "r"); if (fp == NULL) { ... } 4) Are tests for zero more efficently written as if (var) { ... } rather than as if (var != 0) { ... }