Skip to main content
Arduino

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

utf8 to hex macro

I would like to replace utf8 characters to byte values for easier character display handling. The actual replacement table comes from the lcd datasheet therefore it is not utf8 to ascii conversion. Hence I would like to define some macros, where I put the utf8 character, and it returns some matching hex code.

Here is the bare minimum code:

#define IV('┌') 0xC9
#define IV('°') 0xB2
char line0[4] = {0xC9, '4', 0xB2, 0}; // works
char line1[4] = {IV('┌'), '4', IV('°'), 0}; // do not work
void setup() {}
void loop() {}

It does not compile and I must be missing something obvious or rather basic. Any help is much appreciated.

Answer*

Draft saved
Draft discarded
Cancel
2
  • Macros can give weird errors is you do not parenthesize them properly. Here, you have lots of useless parentheses, yet the ones that would be needed to make the macro safe are missing. With only the required parentheses it would look like: #define IV(i) ((i)=='┌' ? 0xc9 : (i)=='⎩' ? 0x15 : (i)=='⎭' ? 0x17 : (i)=='⎰' ? 0x18 : (i)=='°' ? 0xb2 : (i)=='TM' ? 0xd0 : (i)=='Ξ' ? 0xd8 : (i)) Commented Dec 20, 2020 at 20:12
  • @EdgarBonet ty, corrected. Commented Dec 20, 2020 at 20:24

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /