Equivalent macro for "__attribute__" in Visual studio

xxxxx@gmail.com wrote:

Thanks for your support,
Please find the structure of pmmu_cntx.

struct pmmu_cntx {
u64 table_level : 3;
u64 wr_access : 1;
enum page_size page_size :4;
enum mmu_translation translation_type :3;
u64 th : 1;
u64 table_ptr : 40;
u64 ro : 1;
u64 tph : 2;
u64 ns : 1;
u64 st : 8;
}PACKED_ALIGNED; /* struct mmu_cntx [8 byte] */

This structure pmmu_cntx size is 8 byte in GCC compiler, but in visual studio it is 20 bytes. After i added your changes still i am getting 60 bytes for csr_config. could you please explain and let me know how i can achieve it.

You have now had two different people explain this to you. In fact, I
explained this EXACT example. Are you unable to understand the answer?

The C standard does not allow “enum” in a bitfield. Thus, the behavior
is not defined in the spec, and you cannot predict what a compiler will
do. Visual C++ happens to choose difference packing rules than GCC, and
it is entirely allowed to do that.

If you need perfect packing, then you CANNOT use “enums” in a bitfield.
It’s just that simple. Replace the “enum” with u64.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.