What's going on with C Compilers and C99??

A

albert.neu

Hello!

What is a good compiler to use? (for MS Windows, for Linux)
Any recommendations??


What's the point of having a C99 standard, if different compilers
still produce differing results?

The main reason for a standard, is (in my opinion) portabilty and
conformance.

/************** C99 Resources ***************/
C99 Standard(Committee Draft 2005 - ISO/IEC 9899:TC2)
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf

"The New C Standard: A Cultural and Economic Commentary" by Derek M.
Jones
http://www.coding-guidelines.com/cbook/cbook1_0b.pdf
(http://www.knosof.co.uk/cbook/cbook.html)
This is the ultimate C99 reference bible, since it discusses every
sentance of the C99 standard. Wow!





But no one seems to care:
I recently tried a bunch of *free* compilers...

MinGW GCC (no C99 support e.g. printf("%I64d",99999999LL)),
Lcc-Win32,
Pelles C,
Cygwin GCC

and got different results for the same code snippet

/***********************/
#include <stdio.h>
#include <math.h>

int main(void)
{
printf("%f\n", sqrt(4.0L));
printf("%lf\n", sqrt(4.0L));
printf("%Lf\n", sqrt(4.0L)); // printf("%Lf\n", (long
double)sqrt(4.0L));
return 0;
}
/***********************/
(There are probably much better examples, to show how compilers
differ!

I'm (currently) no expert in C, and certainly not on the C99 standard.
(I wonder if the C99 standard specifies, what the ouput of the 3rd
printf should be...)
I get really frustrated when even printf (yes, that "Hello World"
function) differs from implementation to implementation.
printf("%hhd %hd %d %lld", a, b, c, d); // I wonder how many compilers
support this (C99) correctly... try MinGW :)


But if I use a compiler, I expect it to work! and to have predicatable
behaviour! and to implement the C99 standard!


I think C99 has failed, if only a few compilers support it.
(Perennial http://www.peren.com/ conducts conformance tests and only a
handful of compilers are validated as C99-compliant:
http://www.peren.com/pages/cvsa_isocvpl.htm)
Sun Studio 9 seems to be the only free compiler out there, that fully
supports C99. (Wow, maby I should learn and use Solaris)
For the rest... everyone else seems to be doing their own thing:
Microsoft Visual C++ are doing theirs... GCC is doing theirs... and so
on

No one seems to be really interested in following the C99 standard.
Instead everyone is happy to have a compiler that can simply produce
code (C99 is probably an ugly cryptic read anyway) and the game seems
to be played as follows:
"Forget portability! and code for the moment! Adapt your code, till it
works, with the compiler you're using.
If it needs to be ported, do it when it's necessary. Hell, the
compilers will have changed anyway!!"
???
Maby I should follow suit: Code and test it with your compiler, (be
puzzled for a moment), debug and done!

************************>>>
By the way: who is involved in the C99 standard?
Why didn't they invite C compiler writers (Visual C, GCC, Watcom) to
take part??? Is C99 really that hard to implement?


Ok, what about commercial products for C99?
***
Ah, there's Dinkumware (http://www.dinkumware.com/)
They have a library "Dinkum Compleat" that can be bought for either MS
Windows Visual C++ ($200) or Linux GCC ($200) and allows C99 in
addition to many other things (you cannot get the C99 part
seperately). That library can be bought in binary ($200 "Dinkum
Compleat Libraries Binary" for Visual C++ xor Linux GCC, or $400 for
both) or source form ($2300) and is Perennial C99 compliant (see
http://www.peren.com).

***
Ah, there's Comeau C/C++. http://www.comeaucomputing.com/
What an ugly web-page! Ugly use of font, and waving a blinking $50 at
me!
It seems as though Dinkumware libraries are included... oops no
(fooled me)... they are only available... from Dinkumware... for $200
So it seems I need to spend $ (50+200) for Comeau C/C++ with
Dinkumware for C99 compliance.
(Libcomo seems to be Comeau's own C library, but I could not find a
price - and it probably doesn't support C99.)
Ah but wait, in order to use Comeau, I need another compiler... What
is this beast!????

For MS windows: e.g. "Comeau C/C++" & "Visual C++" & "Dinkumware
Libraries" for C99
For Linux: e.g. "Comeau C/C++" & "GCC" & "Dinkumware Libraries" for
C99

OK, so "Comeau C/C++" works like this:
It is a front end that takes your C-code (C1) and generates an
"Intermediate Form" and from that another C code (C2).
Then you use another compiler (Visual C++, or GCC) to compile C2 to
"machine code".
"Comeau C/C++" don't even have their own machine code generator.

I don't see why anyone would use Comeau...

***
Ah, Edison Design Group: http://www.edg.com/ http://www.edg.com/index.php?location=c_frontend
These 4 guys have a front-end that supports C99 (see also
http://www.peren.com/pages/cvsa_isocvpl.htm)
Intel's C++ compiler's front end is based on EDG, as is Comeau's
(http://www.edg.com/index.php?location=faq_q3_who)
Does this mean that Comeau is C99 compliant? (Who knows?:
http://www.thescripts.com/forum/threadnav219651-1-10.html)

SUIF and Zephyr also use EDG
http://www.edg.com/index.php?location=faq_q4_other

Does anyone know if SUIF (with matching EDG front-end
http://suif.stanford.edu/~livshits/cgi-bin/clickthru.cgi) is good?
http://www-suif.stanford.edu/suif/suif2/


Are there any compiler recommendations...
Right now I'm unwilling to use commercial tools.
I think I'll just stick with GCC (in its various forms: Linux, Cygwin,
MinGW) and play the game, accepting that things just aren't perfect.


Any comments or recommendations, tips etc. will be appreciated

Kind regards,
Albert
 
B

Ben Pfaff

(e-mail address removed) writes:

[big rant]
I recently tried a bunch of *free* compilers... [...]
and got different results for the same code snippet

/***********************/
#include <stdio.h>
#include <math.h>

int main(void)
{
printf("%f\n", sqrt(4.0L));

OK. sqrt returns a double, %f takes a double.
printf("%lf\n", sqrt(4.0L));

This is also OK: the 'l' modifier has no effect on %f.
printf("%Lf\n", sqrt(4.0L)); // printf("%Lf\n", (long
double)sqrt(4.0L));

This invokes undefined behavior, because it supplies a double
argument to printf, whereas %Lf requires a long double argument.
return 0;
}
/***********************/

It should not come as a big surprise that undefined behavior
behaves differently on different C implementations.
 
G

Greg Comeau

What's the point of having a C99 standard, if different compilers
still produce differing results?

Not sure what you mean, unless you mean different compilers
claiming to support C99 are producing differering results
for something that is not undefined et al behavior.
 
G

Greg Comeau

/************** C99 Resources ***************/
C99 Standard(Committee Draft 2005 - ISO/IEC 9899:TC2)
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf

"The New C Standard: A Cultural and Economic Commentary" by Derek M.
Jones
http://www.coding-guidelines.com/cbook/cbook1_0b.pdf
(http://www.knosof.co.uk/cbook/cbook.html)
This is the ultimate C99 reference bible, since it discusses every
sentance of the C99 standard. Wow!

Yes, his is an interesting perspective. There as others too,
some of which I note in http://www.comeaucomputing.com/booklist
 
G

Greg Comeau

But no one seems to care:
I recently tried a bunch of *free* compilers...

MinGW GCC (no C99 support e.g. printf("%I64d",99999999LL)),
Lcc-Win32,
Pelles C,
Cygwin GCC

and got different results for the same code snippet

But none of them claim conformance to C99, only partial
features, which they list explicitly.
 
G

Greg Comeau

#include <math.h>

int main(void)
{
printf("%f\n", sqrt(4.0L));
printf("%lf\n", sqrt(4.0L));
printf("%Lf\n", sqrt(4.0L)); // printf("%Lf\n", (long
double)sqrt(4.0L));
return 0;
}
/***********************/
(There are probably much better examples, to show how compilers
differ!

I'm (currently) no expert in C, and certainly not on the C99 standard.
(I wonder if the C99 standard specifies, what the ouput of the 3rd
printf should be...)
I get really frustrated when even printf (yes, that "Hello World"
function) differs from implementation to implementation.

So, this is not a C99 problem at all, but one that exists in
non-C99 compilers, as you've just shown.
 
G

Greg Comeau

I think C99 has failed, if only a few compilers support it.
(Perennial http://www.peren.com/ conducts conformance tests and only a
handful of compilers are validated as C99-compliant:
http://www.peren.com/pages/cvsa_isocvpl.htm)
Sun Studio 9 seems to be the only free compiler out there, that fully
supports C99. (Wow, maby I should learn and use Solaris)
For the rest... everyone else seems to be doing their own thing:
Microsoft Visual C++ are doing theirs... GCC is doing theirs... and so
on

That's always been the case if you look at the history of C.
Anyway, C99 has problems being adopted, for sure, but there are
a bunch of compilers supporting it, as discussed in this NG
from time to time (google for it, IBM, Comeau, Dinkumware, etc).
No one seems to be really interested in following the C99 standard.

That's probably true, but a different issue. But, it probably
presents a circularity.
Instead everyone is happy to have a compiler that can simply produce
code (C99 is probably an ugly cryptic read anyway) and the game seems
to be played as follows:
"Forget portability! and code for the moment! Adapt your code, till it
works, with the compiler you're using.
If it needs to be ported, do it when it's necessary. Hell, the
compilers will have changed anyway!!"
???
Maby I should follow suit: Code and test it with your compiler, (be
puzzled for a moment), debug and done!

Well, it could be argued that C99 itself is what broke porability,
but I'll leave that for others to argue :)
 
G

Greg Comeau

By the way: who is involved in the C99 standard?
Why didn't they invite C compiler writers (Visual C, GCC, Watcom) to
take part???

Participants are volunteers, and incur their own costs, etc. However,
said folks were part of it. There is ANSI, the US committe and
ISO, the international org, both bodies have able minded persons
of the committees, inclouding many/most compiler vendors. It did
not happen in a vaccum.
Is C99 really that hard to implement?

It has its sticking points, but compared to other things
it is generally very doable. So the reason it is not as
popular has to do with other things.
 
G

Greg Comeau

Ok, what about commercial products for C99?
***
Ah, there's Dinkumware (http://www.dinkumware.com/)
They have a library "Dinkum Compleat" that can be bought for either MS
Windows Visual C++ ($200) or Linux GCC ($200) and allows C99 in
addition to many other things (you cannot get the C99 part
seperately). That library can be bought in binary ($200 "Dinkum
Compleat Libraries Binary" for Visual C++ xor Linux GCC, or $400 for
both) or source form ($2300) and is Perennial C99 compliant (see
http://www.peren.com).

Yes, and it's tops.
***
Ah, there's Comeau C/C++. http://www.comeaucomputing.com/
What an ugly web-page! Ugly use of font, and waving a blinking $50 at
me!

That was put there because we literally got thousands of queries
about the price, despite it bring right on the page multiple times
(at least at the time it was), anyway, this is a not a C99 point so...
It seems as though Dinkumware libraries are included... oops no
(fooled me)... they are only available... from Dinkumware... for $200

Nope, nobody fooled you. We sell core language only.
So it seems I need to spend $ (50+200) for Comeau C/C++ with
Dinkumware for C99 compliance.

That sounds correct.
(Libcomo seems to be Comeau's own C library, but I could not find a
price - and it probably doesn't support C99.)

libcomo is C++ only, and actually, it's 100% free.
Ah but wait, in order to use Comeau, I need another compiler... What
is this beast!????
Heh.

For MS windows: e.g. "Comeau C/C++" & "Visual C++" & "Dinkumware
Libraries" for C99
For Linux: e.g. "Comeau C/C++" & "GCC" & "Dinkumware Libraries" for
C99

OK, so "Comeau C/C++" works like this:
It is a front end that takes your C-code (C1)
Yes.

and generates an "Intermediate Form"
Yes.

and from that another C code (C2).
Yes.

Then you use another compiler (Visual C++, or GCC) to compile C2 to
"machine code".
Yes.

"Comeau C/C++" don't even have their own machine code generator.

It's a complete code generator, just that in this case the machine is C.

This is indeed a different perspective, but it works, and works well.
This way we can be faster to market, focus better on the front end,
and then leverage off the back end, which the customer already invested
in, and which the C compiler vendor already tailored to the platform
at hand, including optimizations, etc.
I don't see why anyone would use Comeau...

Why not? You're complaining about no C99 capability, and then you
find one source, and then complain again. Indeed, it needs to be
piecemealed, but in the end it's no functionally different than
products from a single source.

Feel free to email us, since parts of the conversation would be off-topic.
***
Ah, Edison Design Group: http://www.edg.com/ http://www.edg.com/index.php?location=c_frontend
These 4 guys have a front-end that supports C99 (see also
http://www.peren.com/pages/cvsa_isocvpl.htm)
Intel's C++ compiler's front end is based on EDG, as is Comeau's
(http://www.edg.com/index.php?location=faq_q3_who)
Correct.

Does this mean that Comeau is C99 compliant? (Who knows?:
http://www.thescripts.com/forum/threadnav219651-1-10.html)
Yes.

SUIF and Zephyr also use EDG
http://www.edg.com/index.php?location=faq_q4_other

Does anyone know if SUIF (with matching EDG front-end
http://suif.stanford.edu/~livshits/cgi-bin/clickthru.cgi) is good?
http://www-suif.stanford.edu/suif/suif2/

We looked at it a few years back and it was very interesting
but we still going to require lots of work, it wasn't just somthing
you could plug in and just go. It can also only really be
done by folks like us, since end users don't have access to
the internal form being used.
Are there any compiler recommendations...
Right now I'm unwilling to use commercial tools.

Then it sounds like you're stuck in catch-22 C99-wise.
 
C

Chris Dollin

Greg said:
Yes, his is an interesting perspective. There as others too,
some of which I note in http://www.comeaucomputing.com/booklist

I wasn't best pleased by the:

alert('You must have the latest IE or Netscape to see the book blurbs on this page');

(I use Firefox and Konqueror).

--
JUC 2007, submit: http://hpl.hp.com/conferences/juc2007/submission.html
"You've spotted a flaw in my thinking, Trev" Big Al,/The Beiderbeck Connection/

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England
 
R

Richard Heathfield

Chris Dollin said:
I wasn't best pleased by the:

alert('You must have the latest IE or Netscape to see the book
blurbs on this page');

I'm surprised by this. I wouldn't have put Greg down as the kind of
person who required people to be continually scanning the Web just in
case a new release of IE or Netscape meant they had to update their
browser so that they could read some book blurbs! Surely book blurbs
are basically text, which is trivial to encode in the kind of HTML that
even an ancient lynx can render?
(I use Firefox and Konqueror).

I use Galeon by default (because it loads quickly), switching to
something else only if Galeon can't cut it, which is rare. If I have to
switch, I tend to go for Konqueror or possibly a fairly old Netscape.
If that doesn't work, I simply find another site. Easy.
 
N

Nick Keighley

(e-mail address removed) wrote:

But if I use a compiler, I expect it to work! and to have predicatable
behaviour! and to implement the C99 standard!

not many implement C99. Nearly everyone implements C89.
I think C99 has failed, if only a few compilers support it.
(Perennial http://www.peren.com/ conducts conformance tests and only a
handful of compilers are validated as C99-compliant:
http://www.peren.com/pages/cvsa_isocvpl.htm)
Sun Studio 9 seems to be the only free compiler out there, that fully
supports C99. (Wow, maby I should learn and use Solaris)
For the rest... everyone else seems to be doing their own thing:
Microsoft Visual C++ are doing theirs... GCC is doing theirs... and so
on

No one seems to be really interested in following the C99 standard.
Instead everyone is happy to have a compiler that can simply produce
code (C99 is probably an ugly cryptic read anyway) and the game seems
to be played as follows:
"Forget portability! and code for the moment! Adapt your code, till it
works, with the compiler you're using.

or comply with C89
If it needs to be ported, do it when it's necessary. Hell, the
compilers will have changed anyway!!"
???
Maby I should follow suit: Code and test it with your compiler, (be
puzzled for a moment), debug and done!

you can write C89 code that is pretty damn portable.

<snip>
 
G

Greg Comeau

I wasn't best pleased by the:

alert('You must have the latest IE or Netscape to see the book blurbs on this page');

(I use Firefox and Konqueror).

If I recall the original intention, it was to get clutter out of
the list, and it was probably an experiment gone bad on my end anyway
because at least at the time the browsers were so across the board
on how to handle it. So currently you're not missing much by
not seeing the blurb.

.... back to C99...
 
J

JimS

Hello!
Hello.

By the way: who is involved in the C99 standard?
Why didn't they invite C compiler writers (Visual C, GCC, Watcom) to
take part??? Is C99 really that hard to implement?

OpenWatcom is an open source C compiler. Work is ongoing to make it a
C99 compliant compiler. If you'd like to help us achieve that goal,
come over to www.openwatcom.com and join in with the development
effort. I don't think we presently make any claims about being
compliant with C99.

Who is involved in the C99 standard? As I understand it, anyone can
make a submission.

Jim
 
J

J. J. Farrell

What is a good compiler to use? (for MS Windows, for Linux)
Any recommendations??

What's the point of having a C99 standard, if different compilers
still produce differing results?

Knowing when to expext differing results.
The main reason for a standard, is (in my opinion) portabilty and
conformance.

Indeed, that's why they're useful.
...

But if I use a compiler, I expect it to work! and to have predicatable
behaviour! and to implement the C99 standard!

Why do you expect it to implement C99? If there's little demand for
it, why should it?
I think C99 has failed, if only a few compilers support it.

As of now that's true; and it's hardly news.
No one seems to be really interested in following the C99 standard.
Instead everyone is happy to have a compiler that can simply produce
code (C99 is probably an ugly cryptic read anyway) and the game seems
to be played as follows:
"Forget portability! and code for the moment! Adapt your code, till it
works, with the compiler you're using.
If it needs to be ported, do it when it's necessary. Hell, the
compilers will have changed anyway!!"

Utter nonsense. People writing portable code stick to C90, possibly
also bravely using some of the widely implemented C99 extensions.
...

Any comments or recommendations, tips etc. will be appreciated

Stick to C90.
 
C

Chris Hills

Nick said:
(e-mail address removed) wrote:



not many implement C99. Nearly everyone implements C89.

You probably mean ISO C (ISO 9899:1990) with A1 and the TC's for 1993

So most refer to it as C95 (which is when the last major TC was added).
Most compilers are actually C95+ (bits of C99)
 
N

Nick Keighley

Chris said:
You probably mean ISO C (ISO 9899:1990) with A1 and the TC's for 1993

So most refer to it as C95 (which is when the last major TC was added).
Most compilers are actually C95+ (bits of C99)

yes but they don't implement the *same* bits. Which effectively makes
C99
non-portable.
 
C

Chris Hills

Nick said:
yes but they don't implement the *same* bits. Which effectively makes
C99
non-portable.
I agree totally.

I was querying your comment that most implement C89. You meant C90 + A1
and TC's
 
K

Keith Thompson

Chris Hills said:
I agree totally.

I was querying your comment that most implement C89. You meant C90 +
A1 and TC's

C90 + A1 and TC's is C95, right?

Well, a compiler that implements C95 also implements C89 (the language
defined by the 1989 ANSI standard, which is the same language as the
one defined by the 1990 ISO standard), right?

I wonder, are there any implementations (note: this includes both the
compiler and the runtime library) that support C90 but *not* C95? For
purposes of this question, consider a compiler with different
command-line options to be the same implementation.

<OT>gcc uses "--std=iso9899:199409" to specify C95 conformance.</OT>
 
B

Ben Pfaff

Keith Thompson said:
I wonder, are there any implementations (note: this includes both the
compiler and the runtime library) that support C90 but *not* C95? For
purposes of this question, consider a compiler with different
command-line options to be the same implementation.

I imagine that Turbo C 3.0 does not support C95. (It was
released in 1991.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top