   Please help me to understand this line
  I am reading a C++ program, and the following line really gives me a headache. Does anybody know something about this type of assignment? To me the bitwise operator is really abused here.const int MAX_PACKETS = 1 | 30 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 10 | 10 | 1 | 16 | CONFIG_MAX; //what is this for?andconst int MAX_TEST = 1 | 30 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 16; //What is its value?Thanks in advance.Johnson   
  LOL? Anyway, try running those through a simple console program and cout the value ;)   ;Quote:Original post by KalasjniekofLOL? Anyway, try running those through a simple console program and cout the value ;)then slap the person who wrote that program...all the |1's, as can other repeats, can be copacted into one of them, they read like soconst int MAX_PACKETS = 1 | 30 | 10 | 16 | CONFIG_MAX; const int MAX_TEST = 1 | 30 | 16; ;  I don't think the person that wrote those snippets knew what he was doing. Compare the output from those snippets with these. const int MAX_PACKETS = 1 | 30 | CONFIG_MAX;const int MAX_TEST = 1 | 30;;  This looks like somebody was trying to be clever.Quote:const int MAX_TEST = 1 | 30 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 16; //What is its value?I'm guessing there are 12 tests, the first is of size 1, the second of size 30, the third 1, and so on.  By bitwise-or'ing them all together you get a (loose) upper bound on the maximum size of any one test.I wouldn't recommend copying this example.  It's hard to understand and maintain.  At the very least there needs to be a comment explaining why they're doing something so wierd.   ;  Thanks for your help.I still could not understand why that guy made this joke on the program. There are lots of easier and clearer ways to do the same task.Johnson   ;  Wow, thats bad code. Well, the first thing to do to make sense of it is to realizes that 1 | 1 == 1. Now, if it were 16, 32, 64, I'd say it was boolean operators being used as bitmasks, but 10? 30? No, thats not understanding how bits work.10|1==1130|1==3110|30==301|10|30==31So, what we have here is code that doesn't make sense.   ;  Maybe the ones are intended as placeholders for other values to be added later? Somebody heard that you need to make code that can easily be extended, so he made room for other tests.   ;  ...Lol   ;Quote:Original post by Anon MikeThis looks like somebody was trying to be clever.Quote:const int MAX_TEST = 1 | 30 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 16; //What is its value?By bitwise-or'ing them all together you get a (loose) upper bound on the maximum size of any one test.I think you hit the nail on the head.  $5 says that it would make a little more sense if the usage of MAX_TEST and the other var is shown.  Each of the values between the bitwise-or's most likely represents ... something .. that needs to be tested.  By bitwise or'ing the test count (??) of each of the .. somethings .. you get a very loose upperbound.  Probably the programmer's idea of easily manipulating the upperbound without going through some sort of loop to find the max of an abritrary number of .. somethings ..Either way, someone needs to be punched in the gut for that :)  hehehe   