tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] What C version tcc is supposed to implement?


From: Michael Matz
Subject: Re: [Tinycc-devel] What C version tcc is supposed to implement?
Date: Sat, 16 Feb 2013 19:57:45 +0100
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/17.0 Thunderbird/17.0

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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]