'??' converts to '^' in Visual C ++. Why is this happening and what is the way out?

'??' converts to '^' if I compile mn VC ++ program and run it

eg.

sprintf( ch, "??") 

      

deduces

^

      

But if I run the same code in Turbo C / C ++ there is no such problem. Why does this happen in VC ++ on Windows?

+2


a source to share


3 answers


??

is not trigraph although it ??'

fits ^

.

You may have typed it here, different from what you have in your code, and you cannot see the trailing single quote in your string because it is too close to the closing quote.



So, in your code, you have:

sprintf( ch, "??'");

      

+4


a source


Are you sure it was a double quote and not a single quote? If it was? "Then you just met trigraph , which is a" feature "that really needs to be removed, but not because IBM didn't migrate to UTF-8 from EBCDIC . (Trigraphs were considered for removal when C ++ 0x was still open to change, but the move to remove trigraphs was violently blocked by IBM and its representatives on the ISO C ++ committee).



+4


a source


Usually the sequence ??

starts the trigraph, but the "??" is not a trigraph so it cannot be interpreted as such - maybe there is a bug in the compiler - exactly which version you are using and what is the exact code (including variable declarations)?

This code prints "??" in multiple versions of MSVC 6 prior to VS 2010, as you might expect:

char ch[20];
sprintf( ch, "??");
printf( "%s\n", ch);

      

But replace the line snprintf()

with:

sprintf( ch, "'??'");

      

and the output becomes " '^

" (except VS 2010).

A quick test shows that VS 2010 disables trigraph support by default (it outputs " '??'

" in the second test). In VS 2010, you must explicitly enable trigraph support using the option /Zc:trigraphs

. Nice.

For more on what trigraphs are, see: Assigning Trigraph Sequences in C ++?

+3


a source







All Articles