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: Christian Jullien
Subject: Re: [Tinycc-devel] What C version tcc is supposed to implement?
Date: Sat, 16 Feb 2013 20:16:59 +0100

Thank you Michael,

I'm really sorry, my intention was not that someone tried to debug this
silly program.
The purpose of this small program was to illustrate that I don't know what C
version tcc is supposed to implement, with which feature.
I admit that this quick and dirty program is odd.

If __STDC_VERSION__ is set to 199901L we can assume that other features of
ISO/IEC 9899:1999 (E) are present which it not true.

Christian

-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of
Michael Matz
Sent: samedi 16 février 2013 19:58
To: address@hidden
Subject: Re: [Tinycc-devel] What C version tcc is supposed to implement?

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
address@hidden
https://lists.nongnu.org/mailman/listinfo/tinycc-devel




reply via email to

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