[misc.jobs.misc] C test

mc68020@gilsys.UUCP (Thomas J Keller) (07/31/87)

   I recently posted regarding the nasty little pointer problem I encountered
on a "programming test" popped on me by a job shop.  Here is another of the
little gems from that test.  I just *LOVE* this one!

Improve the following code fragment through reorganization:

{
    if (A) { B; return; }
    if (C) { D; return; }
    if (E) { F; return; }
    G; return;
}


   Cute, eh?  The thing that's ironic about it is that this is typical of the
quality and scope of the specifications I have been handed by employers for
PRODUCTION coding!  No wonder to me that there are so many buggy, slow, pain-
in-the-arse programs out there!

-- 
Tom    : The conservatives always grouse about "Law & Order" when the liberals
Keller : break the law...when the Reagan Admin. does it, it's PATRIOTISM!

UUCP   : {ihnp4,ames,qantel,sun,amdahl,lll-crg,pyramid}!ptsfa!gilsys!mc68020
BITNET : ptsfa!gilsys!mc68020@ames.com

ron@topaz.rutgers.edu (Ron Natalie) (08/04/87)

{
    if (A) { B; return; }
    if (C) { D; return; }
    if (E) { F; return; }
    G; return;
}

is efficiently replaced by

{ return; }

since the computed values B, D, F, and G are ignored.  Unless, the
symbols A through G are supposed to indicate arbitrary expressions
that have side effects such as assignments or function calls in them.

-Ron

scott@applix.UUCP (Scott Evernden) (08/04/87)

In article <1090@gilsys.UUCP> mc68020@gilsys.UUCP (Thomas J Keller) writes:
>Improve the following code fragment through reorganization:
>{
>    if (A) { B; return; }
>    if (C) { D; return; }
>    if (E) { F; return; }
>    G; return;
>}

An improvement?: 
{
	A ? B : C ? D : E ? F : G;
}
which generates exactly the same code on my sun.

-scott