Make `gb.h` compatible with C++ again for bsnes integration. Fixed #300

This commit is contained in:
Lior Halphon 2020-10-09 16:39:23 +03:00
parent 7c92845882
commit c35fe8b517
1 changed files with 6 additions and 0 deletions

View File

@ -5,10 +5,16 @@
#define GB_PADDING(type, old_usage) type old_usage##__do_not_use
#ifdef __cplusplus
/* For bsnes integration. C++ code does not need section information, and throws a fit over certain types such
as anonymous enums inside unions */
#define GB_SECTION(name, ...) __attribute__ ((aligned (8))) __VA_ARGS__
#else
#define GB_SECTION(name, ...) __attribute__ ((aligned (8))) union {uint8_t name##_section_start; struct {__VA_ARGS__};}; uint8_t name##_section_end[0]
#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))
#endif
#define GB_aligned_double __attribute__ ((aligned (8))) double