# S2806 / M23_159: Bit fields should not be used
id: no-bit-fields
name: Bit Fields Should Not Be Used
severity: error
category: maintainability
defect_class: correctness
inline_tier: blocking
language: c

message: "bit fields should not be used — layout is implementation-defined and non-portable"

description: |
  Bit-field layout (ordering, padding, sign behavior) is implementation-
  defined in C. They break portability and can lead to subtle bugs.

  ✅ FIX: Use explicit masks and shifts, or sized integer types

  ```c
  typedef uint8_t Flags;
  #define FLAG_A 0x01
  #define FLAG_B 0x02
  ```

query: |
  (field_declaration
    (bitfield_clause) @BITFIELD) @DECL

metavars:
  - BITFIELD
  - DECL

tags:
  - maintainability
  - c
  - portability
  - performance

examples:
  bad: |
    struct {
        int flag : 1;   // BAD
        int value : 7;  // BAD
    };

  good: |
    typedef uint8_t Flags;  // GOOD - explicit width

has_fix: false
