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

2013-02-27 Thread Thomas Preud'homme
Le dimanche 17 février 2013 21:00:56, Christian Jullien a écrit :
> _ _STDC_HOSTED_ _ The integer constant 1 if the implementation is a hosted
> implementation or the integer constant 0 if it is not.
> 
> What NULL means? Is __STD__HOSTED__ is defined or not? With which value?
> 
> To me:
> _ _STDC_HOSTED_ _ == 1 mean hosted
> _ _STDC_HOSTED_ _ == 0 mean NOT hosted, no main, stdout, stdin ...
> Not defined: don't know, "probably" hosted yet not sure.
> 
> If we decide to define this macro it should be set to 1

NULL means defined to 1. See code of tcc_define_symbol.

> 
> C.

Thomas


signature.asc
Description: This is a digitally signed message part.
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


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

2013-02-17 Thread Thomas Preud'homme
Le dimanche 17 février 2013 21:00:56, Christian Jullien a écrit :
> _ _STDC_HOSTED_ _ The integer constant 1 if the implementation is a hosted
> implementation or the integer constant 0 if it is not.
> 
> What NULL means? Is __STD__HOSTED__ is defined or not? With which value?
> 
> To me:
> _ _STDC_HOSTED_ _ == 1 mean hosted
> _ _STDC_HOSTED_ _ == 0 mean NOT hosted, no main, stdout, stdin ...
> Not defined: don't know, "probably" hosted yet not sure.
> 
> If we decide to define this macro it should be set to 1

Woops, bad copy/paste.

> 
> C.

Thanks Christian,

Thomas


signature.asc
Description: This is a digitally signed message part.
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


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

2013-02-17 Thread Christian Jullien
_ _STDC_HOSTED_ _ The integer constant 1 if the implementation is a hosted
implementation or the integer constant 0 if it is not.

What NULL means? Is __STD__HOSTED__ is defined or not? With which value?

To me:
_ _STDC_HOSTED_ _ == 1 mean hosted
_ _STDC_HOSTED_ _ == 0 mean NOT hosted, no main, stdout, stdin ...
Not defined: don't know, "probably" hosted yet not sure.

If we decide to define this macro it should be set to 1

C.


-Original Message-
From: tinycc-devel-bounces+eligis=orange...@nongnu.org 
[mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] On Behalf Of Michael 
Matz
Sent: dimanche 17 février 2013 20:12
To: tinycc-devel@nongnu.org
Subject: Re: [Tinycc-devel] What C version tcc is supposed to implement?

Am 17.02.2013 19:46, schrieb Thomas Preud'homme:
> Le samedi 16 février 2013 21:17:32, Michael Matz a écrit :
>> __STDC_HOSTED__  : not set (incorrectly, it should probably be set to 1
>>  given that tcc assumes a normal main() and that the
>>  rest of the provided facilities is provided by the C
>>  library not under tcc control)
>
> So what do you think of the attached patch?

Makes sense IMO.


Ciao,
Michael.


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


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


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

2013-02-17 Thread Michael Matz

Am 17.02.2013 19:46, schrieb Thomas Preud'homme:

Le samedi 16 février 2013 21:17:32, Michael Matz a écrit :

__STDC_HOSTED__  : not set (incorrectly, it should probably be set to 1
 given that tcc assumes a normal main() and that the
 rest of the provided facilities is provided by the C
 library not under tcc control)


So what do you think of the attached patch?


Makes sense IMO.


Ciao,
Michael.


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


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

2013-02-17 Thread Thomas Preud'homme
Le samedi 16 février 2013 21:17:32, Michael Matz a écrit :
> __STDC_HOSTED__  : not set (incorrectly, it should probably be set to 1
> given that tcc assumes a normal main() and that the
> rest of the provided facilities is provided by the C
> library not under tcc control)

So what do you think of the attached patch?

Best regards,

Thomas
From fe64a4d00512740b3cd3a8faa49ba7c908e86944 Mon Sep 17 00:00:00 2001
From: Thomas Preud'homme 
Date: Sun, 17 Feb 2013 19:44:55 +0100
Subject: [PATCH] Define __STDC_HOSTED__

Quoting Michael Matz on tinycc-devel:

"__STDC_HOSTED__  : not set (incorrectly, it should probably be set to 1
given that tcc assumes a normal main() and that the
rest of the provided facilities is provided by the C
library not under tcc control)"
---
 libtcc.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/libtcc.c b/libtcc.c
index 6b8f237..b138fd9 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -924,6 +924,7 @@ LIBTCCAPI TCCState *tcc_new(void)
 /* standard defines */
 tcc_define_symbol(s, "__STDC__", NULL);
 tcc_define_symbol(s, "__STDC_VERSION__", "199901L");
+tcc_define_symbol(s, "__STDC_HOSTED__", NULL);
 
 /* target defines */
 #if defined(TCC_TARGET_I386)
-- 
1.7.10.4



signature.asc
Description: This is a digitally signed message part.
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


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

2013-02-16 Thread Christian Jullien

> So, in short, if your question was really only the subject: tcc aims to a
large subset of ISO/IEC 9899:1999, hosted implementation, minus _Complex and
minus IEC 559.  Modulo bugs, and modulo missing features I forgot :), if you
have any specific in mind, tell us.

Yes, and you replied to my question perfectly.

This is a guidance on how tcc should evolve (toward better, possibly full,
ISO/IEC 9899:1999 (E) support).

Having ported some of my projects on more than 100 different systems, I rely
on what C macros tells me to try to have a "portable" source code. POSIX
macros also give me hints of what I can use.
autoconf + ./configure is one help but, unfortunately, it does on run on all
possible system. I member the nightmare to port on Vax VMS, IBM OS390 not
counting exotic systems like BeOS, SkyOS, QNX ...  

Christian

-Original Message-
From: tinycc-devel-bounces+eligis=orange...@nongnu.org
[mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] On Behalf Of
Michael Matz
Sent: samedi 16 février 2013 21:18
To: tinycc-devel@nongnu.org
Subject: Re: [Tinycc-devel] What C version tcc is supposed to implement?

Am 16.02.2013 20:16, schrieb Christian Jullien:
> 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.

Then you have to be a bit more specific about which features you're missing,
as wchar_t's aren't.  There are of course some, but usually arcane ones that
even GCC doesn't implement (e.g. strict adherence to the floating point
environment model, and the associated pragmas).

I can tell you that tcc aims to implement c99 (when reasonably possible), so
setting __STDC_VERSION__ to the value it has right now is sensible.  Not
necessarily all optional features of it (e.g. _Complex support is missing
right now, but that's mentioned in the TODO).  You cited some macros that
are supposed to be set, and the state of them is:

__STDC__ : set correctly
__STDC_VERSION__ : set correctly
__STDC_HOSTED__  : not set (incorrectly, it should probably be set to 1
given that tcc assumes a normal main() and that the
rest of the provided facilities is provided by the C
library not under tcc control) __STDC_IEC_559__ :
Optional, correctly not set __STDC_IEC_559_COMPLEX__ : Optional, correctly
not set
__STDC_ISO_10646 : Optional, setting it would require quite some
testing because it would have to be matched against
a certain version of the 10646 standard.  Not much
value in doing that.

So, in short, if your question was really only the subject: tcc aims to a
large subset of ISO/IEC 9899:1999, hosted implementation, minus _Complex and
minus IEC 559.  Modulo bugs, and modulo missing features I forgot :), if you
have any specific in mind, tell us.


Ciao,
Michael.

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


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


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

2013-02-16 Thread Michael Matz

Am 16.02.2013 20:16, schrieb Christian Jullien:

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.


Then you have to be a bit more specific about which features you're
missing, as wchar_t's aren't.  There are of course some, but usually
arcane ones that even GCC doesn't implement (e.g. strict adherence to
the floating point environment model, and the associated pragmas).

I can tell you that tcc aims to implement c99 (when reasonably
possible), so setting __STDC_VERSION__ to the value it has right now is
sensible.  Not necessarily all optional features of it (e.g. _Complex
support is missing right now, but that's mentioned in the TODO).  You
cited some macros that are supposed to be set, and the state of them is:

__STDC__ : set correctly
__STDC_VERSION__ : set correctly
__STDC_HOSTED__  : not set (incorrectly, it should probably be set to 1
   given that tcc assumes a normal main() and that the
   rest of the provided facilities is provided by the C
   library not under tcc control)
__STDC_IEC_559__ : Optional, correctly not set
__STDC_IEC_559_COMPLEX__ : Optional, correctly not set
__STDC_ISO_10646 : Optional, setting it would require quite some
   testing because it would have to be matched against
   a certain version of the 10646 standard.  Not much
   value in doing that.

So, in short, if your question was really only the subject: tcc
aims to a large subset of ISO/IEC 9899:1999, hosted implementation,
minus _Complex and minus IEC 559.  Modulo bugs, and modulo missing
features I forgot :), if you have any specific in mind, tell us.


Ciao,
Michael.

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


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

2013-02-16 Thread Christian Jullien
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: tinycc-devel-bounces+eligis=orange...@nongnu.org
[mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] On Behalf Of
Michael Matz
Sent: samedi 16 février 2013 19:58
To: tinycc-devel@nongnu.org
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
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


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


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

2013-02-16 Thread Michael Matz

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


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

2013-02-16 Thread Christian Jullien
tcc_define_symbol(s, "__STDC_VERSION__", "199901L");

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

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

#include 
#include 

int main()
{
#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]);
printf("%x %x %x %x\n", p[4],p[5],p[6],p[7]);
wprintf(L"Hello World\n");
#else
printf("Not an ISO C compiler\n");
#endif
}

It compiles with no error on RPi, treats wchar_t as an uint32_t (as on
Linux) yet does nothing with wprintf!
jullien@sims ~ $ tcc foo.c -o foo && ./foo
41 0 0 0
42 0 0 0
jullien@sims ~ $

If tcc is 199901L, as said in ISO/IEC 9899:1999 (E) it should also define:

_ _STDC_ _ The integer constant 1, intended to indicate a conforming
implementation.
_ _STDC_HOSTED_ _ The integer constant 1 if the implementation is a hosted
implementation or the integer constant 0 if it is not.
_ _STDC_VERSION_ _ The integer constant 199901L
_ _STDC_IEC_559_ _ The integer constant 1, intended to indicate conformance
to the
specifications in annex F (IEC 60559 floating-point arithmetic).
_ _STDC_IEC_559_COMPLEX_ _ The integer constant 1, intended to indicate
adherence to the specifications in informative annex G (IEC 60559
compatible complex arithmetic).
_ _STDC_ISO_10646_ _ An integer constant of the form mmL (for example,
199712L), intended to indicate that values of type wchar_t are the
coded representations of the characters defined by ISO/IEC 10646, along
with all amendments and technical corrigenda as of the specified year and
month.


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