Suppose we have the following C source:

typedef struct {
  int bit0 : 1;
  int bit1 : 1;
  int bit2 : 1;
  int bit3 : 1;
} bit_struct;

bit_struct a;

void setBit3()
  a.bit3 = 1;

When we compile it and open the result in Ghidra, the decompilation window shows

void setBit3(void)
  a = a | 8;

If we give Ghidra the declaration of bit_struct (using File -> Parse C Source), and then go to the location of a and set its data type to bit_struct, the decompilation changes to

a = (bit_struct)((byte)a | 8);

which still doesn't access bit3 by declared name.

How can we make Ghidra properly decompile it?

1 Answer 1


Looks like full bitfield support for the decompiler is slated for a future release according to a comment on Ghidra's github issues: Bitfields don't seem to decompile very well #1059

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.