'SET_ON' in C programming
An answer to this question on Stack Overflow.
Question
When I was reading the C programming language book, I came across this:
x = x | SET_ON;
What does this do? Is 'SET_ON' a keyword in C? Or does the author just try to explain what '|' does?
Answer
The pipe symbol | takes two variables and does a bitwise-or on them.
The truth table for bitwise-or is:
A | B | Result
0 | 0 | 0
0 | 1 | 1
1 | 0 | 1
1 | 1 | 1
So, if x is A in the truth table and you want to "turn on" a bit, you'd have B equal one. Otherwise, x is unaffected.
Of course that only tells us the idea, not what SET_ON is doing specifically. For instance, if SET_ON=0xFF, then it turns on all the bits (in the least-significant byte).
SET_ON is not part of the C language: it is defined by whatever library or code you're looking at. If you can't find the definition, you'll have to figure it out from context/description.