CKTIS / C
Bitwise OR assignment operator (|=)
The |= operator stores the operands’ bitwise OR in the left operand. Use it to set mask bits.
Version: C23; repository compiler flag, production runtime not attested
Syntax
lhs |= rhslhs |= rhs requires integer operands; lhs must be a modifiable lvalue. A bit in the intermediate OR result is set if the corresponding bit is set in at least one of the converted operands.
For non-atomic lhs, this corresponds to lhs = lhs | (rhs), but lhs is evaluated only once. The usual arithmetic conversions apply, and the result is converted to the type of lhs when stored; a narrower type can lose bits.
The bitwise OR preserves set operand bits in the intermediate result, but conversion to the type of lhs can change which bits are set in the stored value. Unlike logical ||, |= does not short-circuit. In the example, setting the same flag again leaves the result unchanged.
Examples
#include <stdio.h>
int main(void)
{
unsigned int flags = 1u;
flags |= 4u;
flags |= 4u;
printf("%u\n", flags);
return 0;
}
Result
5
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.