Skip to content

Files

Latest commit

 

History

History
21 lines (13 loc) · 451 Bytes

charBitOp.md

File metadata and controls

21 lines (13 loc) · 451 Bytes

Pattern: Use of char variable in bit operation

Issue: -

Description

When using char variables in bit operations, sign extension can generate unexpected results. For example:

    char c = 0x80;
    int i = 0 | c;
    if (i & 0x8000)
        printf("not expected");

The "not expected" will be printed on the screen.

Further Reading