Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!husc6!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c,misc.jobs.misc Subject: Re: weird c code/ c test Message-ID: <6204@brl-smoke.ARPA> Date: Thu, 30-Jul-87 23:59:43 EDT Article-I.D.: brl-smok.6204 Posted: Thu Jul 30 23:59:43 1987 Date-Received: Sat, 1-Aug-87 15:22:41 EDT References: <1089@gilsys.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 43 Keywords: test, employment, weird, code, pointers Xref: mnetor comp.lang.c:3392 misc.jobs.misc:525 In article <1089@gilsys.UUCP> mc68020@gilsys.UUCP (Thomas J Keller) writes: >char ****cpp = cp; The above has one too many *s. > printf("%s ", *--*++cpp+3); The operand of -- is not a modifiable lvalue of scalar type, so this expression is illegal. >} This program returns a random value to the invoking environment. > (actually, the program AS PRESENTED probably wouldn't have compiled, as > the *c declaration was as follows: > char *c[] = { "ENTER", "NEW", "POINT", "FRIST", }; > ) Shouldn't that be "FIRST"? No, that's one thing they did correctly. C has always allowed the extra comma after the last initializer in an initializer list. The main reason for that is uniformity, which can be important when automatically generating C source code or when manually editing such a list. > I do question this as a test, however. That is some pretty esoteric >pointer manipulation there! What do you think? It's clear that that style is not acceptable for production code, but presumably the test was intended only to determine how well you knew the rules for C pointers. It's quite possible that they were also trying to see if you could spot the errors in the code. It's hard to say what's "fair" in a test; it mostly depends on what the test is attempting to determine. My previous employer used an applicant screening test for EEs and I helped draw up an analogous one for software engineers. One of our test questions was basically asking for a solution to the problem of clipping a line segment to a rectangular window, and the specification was left fairly loose on purpose. We were not looking for a solution (we already had one), but rather for evidence of how the applicant went about approaching such a problem. In the test you quoted, I would give points for itemizing the actual storage cells for the variables, writing their initial values, and then updating their contents as they were modified during the run sequence. I would also give points for rewriting cp as &cp[0], and so forth. Identifying the bugs would score points, too.