Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Work around typedef u8 to use C++11 u8 string literal

I'd like to use the new C++ u8 string literal prefix (reference).

However the code base I'm using already typedefs u8 to be unsigned char. I can't practically move headers around or #undef around them.

How may I work around this?

like image 945
Greg Avatar asked Dec 11 '22 07:12

Greg


1 Answers

It does not matter that u8 has been defined as a macro. A string literal, whether or not it has an encoding prefix, is a single preprocessor token. The u8 prefix will not undergo macro replacement. There is actually an example in Appendix C that demonstrates this:

#define u8 "abc"
const char *s = u8"def";  // Previously "abcdef", now "def"
like image 129
Brian Bi Avatar answered Dec 29 '22 00:12

Brian Bi