Hello Christian,

Am 16.02.2013 12:04, schrieb Christian Jullien:
     tcc_define_symbol(s, "__STDC_VERSION__", "199901L");

This define pretends it is ISO/IEC 9899:1999 (E)

Strictly speaking that's optimistic, because it also depends on the C library on which tcc has no influence (some embedded C libs can be configured to not support wchar for instance). But in your case it's simply an error on your part.

Because __STDC_VERSION__ is set to 199901L
This code should be legal:

It's legal, but doesn't do what you want:

int main()
{

When a program is started stdout/err/in have no orientation yet. The first input/output operation determines which orientation it gets ...

#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
         wchar_t* s = L"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
         char* p = (char*)s;
         printf("%x %x %x %x\n", p[0],p[1],p[2],p[3]);

... and printf is byte-oriented, so stdout will from now on be byte-oriented, and the string is output...

         printf("%x %x %x %x\n", p[4],p[5],p[6],p[7]);

... stdout is byte-oriented, printf is byte-oriented, so the string is output ...

         wprintf(L"Hello World\n");

... and this doesn't work, because stdout is byte-oriented, but wprintf requires a stream that isn't byte-oriented. If you had checked for errors you would have seen one. Once a stream has an orientation it can't be switched anymore. Remove the printf's and leave only wprintf and it works. Alternatively if you want to output wide characters on a byte-oriented stream use printf and %ls. For the whole background see fwide(3) and wprintf(3).


Ciao,
Michael.

_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to