[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: not enough real programmers?



In article <ufemh248ig.fsf@jtc-home-pc.redback.com>,
J.T. Conklin <jtc@jtc-home-pc.redback.com> wrote:
>jon@axtell.obvious.demon.co.uk (Jon Axtell) writes:

>> When I was interviewing people (and I have interviewed over 100
>> engineers) I made up a simple questionaire which was deliberately
>> open-ended. It was a more look at this sample of code, and discuss.
>> It's aim was to get the engineer to talk about the code sample and
>> from their views I got a very good impression of what kind of
>> programmer they were, and also if they /really/ knew C.
>> 
>> The questions were like...
>> 1) if (toupper( *ch++)) == 'A') then ch++
>
>> 1) side-effect from ch++ in a macro which is evaluated twice
>
>But in Standard C, toupper() is defined as a function.  If it's also
>implemented as a macro (it must always be implemented as a function,
>so that users can use it via a function pointer), the macro must not
>have side effects.  Back in the dark ages, it couldn't be used safely.
>You also had to ensure that islower(arg) was true, otherwise you might
>get surprising results.

You misunderstood.  The macro isn't toupper(), it's the whole line.  Then
someone put ch++ into the macro and the preprocessor expanded it and ch++
got written twice and ch got interpreted twice instead of once.

Now that I try to reconstruct the original macro definition (without ch++)
it comes out looking meaningless.  I don't know if a macro actually exists
which resembles that line but which (when called with sensible arguments)
produces anything productive that you would WANT to put in C code.

>Another fault with this example is the PASCAL-ization of C with the
>preprocessor to get the 'then' keyword. :-)

I missed that.  Basically, I think the examples were made very quickly. 
You're supposed to notice a certain important flaw and overlook the others. 
In other words, you need to have a certain skill in mind-reading.

-- Derek