How to assign value to a struct with bit-fields?

前端 未结 4 540
耶瑟儿~
耶瑟儿~ 2020-12-30 09:05

I have a struct with bit-fields (totally 32 bit width) and I have a 32-bit variable. When I try to assign the variable value to my struct, I got an error:

4条回答
  •  离开以前
    2020-12-30 09:24

    These are struct members, so you need to assign directly do them, or make sure the RHS of your assignment is a value of type CPUID. Not sure why you expect to be able to assign to the struct from an integer.

    The facts that the struct contains bitfields, and that the sum of the bits happens to be the same as the number of bits in the integer you're trying to assign, mean nothing. They're still not compatible types, for assignment purposes.

    If this was too vague, consider showing more/better code.

提交回复
热议问题