Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!rutgers!mit-eddie!cybvax0!frog!john From: john@frog.UUCP (John Woods, Software) Newsgroups: comp.lang.c Subject: Re: C test Message-ID: <1545@frog.UUCP> Date: Fri, 7-Aug-87 21:09:00 EDT Article-I.D.: frog.1545 Posted: Fri Aug 7 21:09:00 1987 Date-Received: Sun, 9-Aug-87 11:07:27 EDT References: <1090@gilsys.UUCP> <2550025@hpisod2.HP.COM> Organization: Superfrog Heaven [ CRDS, Framingham MA ] Lines: 37 Summary: pessimization In article <2550025@hpisod2.HP.COM>, decot@hpisod2.HP.COM (Dave Decot) writes: > > Improve the following code fragment through reorganization: > > { > > if (A) { B; return; } > > if (C) { D; return; } > > if (E) { F; return; } > > G; return; > > } > I have several answers to this; each would be the "right" answer depending > on who is asking the question and what hidden agenda they have. > 1) Since we do not know whether the definitions, if any, of A, B, C, etc., > contain imbalanced syntactic tokens, there is no way to change this > fragment without possibly breaking the code. > 2) { if (A) B; > else if (C) D; > else if (E) F; > else G; > return; > } > 3) To me, the correct answer is: 4) "That's not my job. That's the job of the compiler writer." Although the lettered code blocks aren't given, when I assume them to be function calls, the Greenhills C compiler generates identical code for the original and for the classical reorganization given. Think of this test not so much as a test of your abilities, as a test of whether or not you want to work for the clown that asked it... -- John Woods, Charles River Data Systems, Framingham MA, (617) 626-1101 ...!decvax!frog!john, ...!mit-eddie!jfw, jfw%mit-ccc@MIT-XX.ARPA "The Unicorn is a pony that has been tragically disfigured by radiation burns." -- Dr. Science