For uncertainty issues, find a way to confirm, or wait for you will be a Bug-programming experience
 
When I added a control and monitoring module to the project in Nanjing last month, I wrote the Code. The Code contains the following sentence:
[Cpp]
If (indicator & 0x8000 = 0x8000 ){
Do something
}
Here, indicator is int type. I mean, if the 16th bits of indicator are 1, execute the statement in brackets, that is, the 16th bits of indicator are a flag. I think so much when writing code, and I think so many days after writing it. However, my buddy in Nanjing told me that the program is not running correctly. If I look at the code myself, I still find that there is no problem. However, I have been told many times that computers will not treat a programmer casually. Since the program is incorrect, the Bug actually exists. After investigation by all parties, I concentrated my focus on the following sentence:
[Cpp]
Task. cur = indicator & 0x7fff;
The intention of this sentence is to remove the flag in indicator and restore the correct value. As mentioned above, indicator is of the int type, that is, 32, while 0x7fff is of the 16 type. So I naturally thought the calculation may be wrong. As you may see, you may have to smile, "you have a tea experience !". Haha, I also Laughed afterwards. No way. When the culprit is not found, the scapegoat is a good way to reduce the psychological pressure. In fact, the calculation here does not cause errors because C has a type improvement. However, I still want to know how the compiler processes constants such as 0x7fff.
Well, then we will do justice for the scapegoat, so we need to find out the culprit. The truth is that "the priority of Relational operators is higher than that of logical operators ". For the operator priority issue, every time I read books on C Programming, I will always jump over, which is too troublesome. I hate to remember those troublesome things, so it becomes an issue of programming uncertainty. However, it is always good to know. However, I still don't remember it. I only leave a consciousness for myself. I will solve such problems in the future. Therefore, even if I do not know the priority, I will write the following statement:
[Cpp]
If (indicator & 0x8000) = 0x8000 ){
Do something
}