Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: comp.lang.c Subject: Re: Portable C vs Efficient C or "Cost of Portability" Message-ID: <7915@utzoo.UUCP> Date: Thu, 16-Apr-87 11:21:03 EST Article-I.D.: utzoo.7915 Posted: Thu Apr 16 11:21:03 1987 Date-Received: Thu, 16-Apr-87 11:21:03 EST References: <213@pyuxe.UUCP> Organization: U of Toronto Zoology Lines: 36 Keywords: portability, performance > If one writes portable C, does it have to be less efficient > than non-portable C ? It depends on what kind of "non-portable C" you are thinking about. C does let you get moderately intimate with the machine if you really want to. On the pdp11, with a compiler that didn't do global optimization, it was possible for someone familiar with the machine to write C in such a way as to control the exact sequence of instructions. (This is the whole reason for the ++ and -- operators, for example, since they allow fairly direct control of the pdp11 autoincrement/decrement addressing modes.) Code that has been done this way for the sake of absolute maximum speed is inherently fairly machine-specific. ON THE OTHER HAND, if the code avoids making stupid assumptions, it WILL work on other machines, although a lot of the efficiency tailoring may be wasted. Such code is usually hard to read, but its meaning is often machine-independent even though the idioms used to express it are not. In the absence of very good compilers, C written without such machine- specific tweaking will be less efficient than C written with it. HOWEVER. If you are not concerned with squeezing every last microsecond out of the code in arcane ways, and are willing to content yourself with the standard of efficiency set by typical C compilers (not superb, but good compared to a lot of other high-level languages and their compilers), the situation changes. Then there is generally little or no penalty for writing portable code, assuming you know what you're doing. Since only a minute fraction of all C code is sufficiently crucial to justify machine-specific code greasing, the best general statement is that well-written portable C is not significantly less efficient than unportable C. This is true even without considering how "efficient" the code is when it won't run on your new faster machine. -- "We must choose: the stars or Henry Spencer @ U of Toronto Zoology the dust. Which shall it be?" {allegra,ihnp4,decvax,pyramid}!utzoo!henry