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.arch,comp.lang.c Subject: Re: String Processing Instruction -- printf, strcpy. Message-ID: <7850@utzoo.UUCP> Date: Tue, 31-Mar-87 15:03:05 EST Article-I.D.: utzoo.7850 Posted: Tue Mar 31 15:03:05 1987 Date-Received: Tue, 31-Mar-87 15:03:05 EST References: <15292@amdcad.UUCP> <978@ames.UUCP> <15694@sun.uucp> Organization: U of Toronto Zoology Lines: 19 Keywords: instruction set architectures, Am29000, printf > Similarly, I have a strong suspicion that compiling strcmp(a,b) to: > > subtract *b from *a > if nonzero, you have the result > else call strcmp() > > (say using the nice _inline_ stuff in the draft C standard) would speed > it up a lot more than all the instructions you could imagine... Careful, John, this code has a bug: on a signed-char machine, the result when comparing "" to "\203" will be wrong. Correct lexical comparison requires that the terminating NUL compare low against all characters, which is not the way subtraction works on a signed-char machine. This will get more important as ISO Latin becomes more common. Admittedly, many existing implementations of strcmp botch this too! -- "We must choose: the stars or Henry Spencer @ U of Toronto Zoology the dust. Which shall it be?" {allegra,ihnp4,decvax,pyramid}!utzoo!henry