#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))    records++;
Feel free to think about that for a second.
(I have an urge to add this to questions asked in a job interview…)
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.
Think of the addition (not bitwise or)
Assuming (as is the case) the flags are powers of 2 (1,2,4,8,…), it’s the same thing as doing bitwise OR
but is semantically wrong. you’re not doing maths at all… it’s all bitwise operations.
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.
Wow, that’s a nice one. I don’t suppose any level of lint checking will warn about it.
Pingback: Tweets that mention Shocked and Stunned (that code exists and does work) | Ramblings -- Topsy.com
Meh. Makes sense to me. But then again, being introduced at any stage of ones life to micro programming can warp ones brain irrepairably.
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?
records here isn’t relevant. it’s about thinking in math when it’s bitwise.
Enter the Philistine… (-:
if (prgflag & (READ_ALL^EXTRA_RECORD))
records++;
…or the masochistic Philistine… (-:
if (prgflag & (READ_ALL¬EXTRA_RECORD))
records++;
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”