Shocked and Stunned (that code exists and does work)

#define READ_ALL		1	/* openfrm: Read all parameters */
#define EXTRA_RECORD		8	/* Reservera plats f|r extra record */

and later on….

  if (prgflag & (READ_ALL+EXTRA_RECORD))

Feel free to think about that for a second.

(I have an urge to add this to questions asked in a job interview…)

12 thoughts on “Shocked and Stunned (that code exists and does work)

  1. It’s not that uncommon to see this… You merely test that there is some shared bits.
    For C programmers this is actually trivial. Somewhat les desired in C++ code.

  2. Yes, but it’s a matter of convention. And the above code is not unpopular. So – if it’s conventional…
    I agree bitwise OR is more appropriate.

  3. Pingback: Tweets that mention Shocked and Stunned (that code exists and does work) | Ramblings --

  4. Meh. Makes sense to me. But then again, being introduced at any stage of ones life to micro programming can warp ones brain irrepairably.

  5. I could be missing something, and I do agree that if records represents something that is a boolean set, then the mathematical ++ operator is inappropriate, regardless of convention.

    But I saw the code as representing something else actually…
    I THOUGHT it was saying :
    If the extra-record bit is set in the program-flag variable, then increment the number of records.

    What is “records”? Is it a binary/boolean or an int / array or struct?

  6. Enter the Philistine… (-:

    if (prgflag & (READ_ALL^EXTRA_RECORD))

    …or the masochistic Philistine… (-:

    if (prgflag & (READ_ALL¬EXTRA_RECORD))

  7. it just works :)
    but ugly code. same behaviour exists in SQL of Drizzle also. sometime back i mailed to discussion group about one accident.
    delete where id-2;
    cleaned up my table.. even if id-2 was not a Boolean type.
    it was a typing mistake and my intention was “id=2”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.