1

I'm having some strange constant/literal generation happening in IAR EW for ARM 8.50 when I declare a specific string:

const char g_string[]="?????-??";

When I look at it in the debugger, it's actually generating the following in memory:

???~??

If I break the string up like so:

const char g_string[]="?????""-??";

I get the expected/desired output:

?????-??

Am I running afoul of some known standard? or is this some IAR specific bug?

FWIW, the literal generated with MSVC and Xtensa/Clang doesn't require this weirdness to get the eight characters as expected.

Edit:

const char g_string[]=R"foo(?????-??)foo"; seems to generate the appropriate characters in memory, so maybe it is a character encoding issue?

phuclv
  • 37,963
  • 15
  • 156
  • 475
Russ Schultz
  • 2,545
  • 20
  • 22
  • Does this answer your question? [What does the ??!??! operator do in C?](https://stackoverflow.com/questions/7825055/what-does-the-operator-do-in-c) – phuclv Oct 22 '21 at 06:53
  • The trick when searching with google is to use literal "question mark" instead of `?`. Duplicates: [What is the meaning of these strange question marks?](https://stackoverflow.com/q/23825603/995714), [Visual Studio 2008: String Literals "??-", "??'", "??=" corrupt](https://stackoverflow.com/q/35503196/995714), [Print ?? and !! in different sequence will show different output](https://stackoverflow.com/q/3862625/995714), [What is the meaning of `???-` in C++ code? (duplicate)](https://stackoverflow.com/q/16662276/995714) – phuclv Oct 22 '21 at 06:57

1 Answers1

1

I found my issue, and it's pretty obscure to an american programmer.

Trigraphs: https://stackoverflow.com/a/1995134/550235

I guess IAR has them enabled by default and the other compilers I'm using don't.

And good luck searching on google for "string literals with ???"

Russ Schultz
  • 2,545
  • 20
  • 22
  • most compilers will warn if you use digraphs or trigraphs. You need to check the warning options of IAR. For example in gcc it's [`-Wtrigraph`](https://stackoverflow.com/a/13619585/995714) – phuclv Oct 22 '21 at 06:51
  • @phuclv the word "trigraph" doesn't show up in the IAR documentation at all, except in their MISRA stuff, so there doesn't seem to be an option to enable or disable trigraphs or warnings. – Russ Schultz Oct 22 '21 at 10:27