I need to default initialize bitfields of my class using c++11 uniform initialization but getting compiler error. Can somebody suggest a work around for this issue. Also I want to know is it possible to pass a constexpr static bool variable in #if directive. This is a sample code:
#include <iostream>
#include <endian.h>
class Endiann {
public:
#ifdef __linux__
#if __BYTE_ORDER == __BIG_ENDIAN
constexpr static BIG_ENDIAN_PRO = true
#elif __BYTE_ORDER == __LITTLE_ENDIAN
constexpr static BIG_ENDIAN_PRO = false
#endif
#endif
#ifdef __WIN32__
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
constexpr static BIG_ENDIAN_PRO = true
#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
constexpr static BIG_ENDIAN_PRO = false
#endif
#endif
static void swap_bytes(char *buff, int32_t sizee) {
char *start = buff, *end = buff + sizee - 1;
while(start < end) {
char swap = *start;
*start = *end;
*end = swap;
++start;
--end;
}
}
};
struct MSG {
int16_t a {};
#if Endiann::BIG_ENDIAN_PRO // getting compiler error here
int16_t b:6 {};
int16_t c:6 {};
int16_t d:4 {};
#else
int16_t d:4 {};
int16_t c:6 {};
int16_t b:6 {};
#endif
};
int main() {
MSG msg; // I know I can use uniform initialization here, but for better assurance I'm using uniform initialization in the struct itself for each member variable
return 0;
}
I'm using gcc and it supports only c++11 standard
Aucun commentaire:
Enregistrer un commentaire