One can assign an ASCII literal (can't call it a string) to enum
value as following:
#include <iostream>
// Macro to handle BIG/LITTLE ENDIAN
// Endianness is suppoesed to handled in this macro
#define TEMP(X) X
enum t
{
XX = 'AA', // 0x4141 or 0100 0001 0100 0001
};
int main()
{
std::cout<<XX<<std::endl;
}
And compiler compiles it and generates a Hexa-decimal constant at compile time, 0x4141
in this case. It does generate a compilation warning as:
main.cpp:9:14: warning: multi-character character constant [-Wmultichar]
XX = 'AA', // 0x4141 or 0100 0001 0100 0001
My question here is, can we avoid this warning?
Or can we write a more elegant code to achieve similar result, probably using templates and constexpr?
I am looking for a portable alternative, so that I can get rid of this as part of refactoring without affecting the core logic.