I came across an odd set of macros in the SameBoy emulator (v0.13) that seems to use an empty struct to address data. It looks like this:
#define GB_PADDING(type, old_usage) type old_usage##__do_not_use#define GB_SECTION(name, ...) \ __attribute__ ((aligned (8))) struct {} name##_section_start; \ __VA_ARGS__; \ struct {} name##_section_end#define GB_SECTION_OFFSET(name) \ (offsetof(GB_gameboy_t, name##_section_start))#define GB_SECTION_SIZE(name) \ (offsetof(GB_gameboy_t, name##_section_end) - offsetof(GB_gameboy_t, name##_section_start))#define GB_GET_SECTION(gb, name) \ ((void*)&((gb)->name##_section_start))
It seems GB_gameboy_t
is a type of some kind (probably for the GameBoy internal structure). However the part that is bothering me is the GB_SECTION
and GB_GET_SECTION
macros. It is clear that the purpose of these macros is to align data. However, I am lost on what an empty struct (labeled name##_section_start
) expands to. Does it expand to nothing (i.e. 0 bytes)? If so, then GB_GET_SECTION
would point to whatever __VA_ARGS__
is. But then what would be the point of the __attribute__ ((aligned (8)))
qualifier? Or does the empty struct expand to some garbage padding bytes? If it does, then GB_GET_SECTION
would point to garbage data.
So which one is it?