Does a C89 compliant compiler exist?

J

Jason Curl

In my previous post I mentioned I'm trying to test the portability of my
C programming (and one big difference I found is the inclusion of header
files matters). Does a fully C89 compliant C compiler exist? That is,
one without fancy extensions, OS agnostic (but of course using the OS
for file I/O)?

Is it then worthwhile to be so pedantic about portability (other than
increasing the chances that software when compiled on other
architectures work with a better probability, but still not guaranteed)
 
G

Grumble

Jason said:
In my previous post I mentioned I'm trying to test the portability of my
C programming (and one big difference I found is the inclusion of header
files matters). Does a fully C89 compliant C compiler exist? That is,
one without fancy extensions, OS agnostic (but of course using the OS
for file I/O)?

Is it then worthwhile to be so pedantic about portability (other than
increasing the chances that software when compiled on other
architectures work with a better probability, but still not guaranteed)

I would think "gcc-3.4.3 -std=c89 -pedantic" fits the bill.
 
L

liessens

Jason said:
In my previous post I mentioned I'm trying to test the portability of my
C programming (and one big difference I found is the inclusion of header
files matters). Does a fully C89 compliant C compiler exist? That is,
one without fancy extensions, OS agnostic (but of course using the OS
for file I/O)?

Is it then worthwhile to be so pedantic about portability (other than
increasing the chances that software when compiled on other
architectures work with a better probability, but still not guaranteed)

According to gcc's manpage:

-std=
Determine the language standard. This option is currently only
supported when compiling C or C++. A value for this option must be

provided; possible values are

c89
iso9899:1990
ISO C90 (same as -ansi).

Benoît
 
D

Dan Pop

In said:
According to gcc's manpage:

-std=
Determine the language standard. This option is currently only
supported when compiling C or C++. A value for this option must be

provided; possible values are

c89
iso9899:1990
ISO C90 (same as -ansi).

That's far from enough: gcc will still silently accept GNU C extensions
that require a diagnostic in the respective language standard:

pub5:~/tmp 15> cat test.c
int main()
{
void *p;
return sizeof *p;
}
pub5:~/tmp 16> gcc -std=c89 test.c
pub5:~/tmp 17>

This option basically disables the GNU C features that conflict with the
standard features, but silently accepts other GNU C features. To get
diagnostics (if diagnostics are required) for those GNU C features,
-pedantic is also required:

pub5:~/tmp 17> gcc -std=c89 -pedantic test.c
test.c: In function `main':
test.c:4: warning: invalid application of `sizeof' to a void type

OTOH, there is no way to get diagnostics for GNU C features that invoke
undefined behaviour if used in a standard C program:

pub5:~/tmp 19> cat test.c
int main()
{
__asm__("nop");
return 0;
}
pub5:~/tmp 20> gcc -std=c89 -pedantic test.c
pub5:~/tmp 21>

So, there is no foolproof method to use gcc as a tester for code
portability across different implementations of the same C standard.

Dan
 
N

not

Is it then worthwhile to be so pedantic about portability (other than
increasing the chances that software when compiled on other
architectures work with a better probability, but still not guaranteed)

The answer to your question lies in analysing the likelihood of your code
being compiled on another platform. If the odds are low or none, then by
all means be as OS specific as you wish. On the other hand...
 
K

Kevin D. Quitt

To get
diagnostics (if diagnostics are required) for those GNU C features,
-pedantic is also required:

I thought in the latest versions the documentation said that the pedantic
option no longer really does anything, and that it's only there for
pedants.
 
J

jacob navia

Kevin said:
I thought in the latest versions the documentation said that the pedantic
option no longer really does anything, and that it's only there for
pedants.

pedants are a big market segment pleeze...

Just look around a bit :)
 
J

Jack Klein

In my previous post I mentioned I'm trying to test the portability of my
C programming (and one big difference I found is the inclusion of header
files matters). Does a fully C89 compliant C compiler exist? That is,
one without fancy extensions, OS agnostic (but of course using the OS
for file I/O)?

Is it then worthwhile to be so pedantic about portability (other than
increasing the chances that software when compiled on other
architectures work with a better probability, but still not guaranteed)

Depends on what you mean by "compliant", a word not defined by the C
standard. If you mean compilers that, when invoked in their most
strictly conforming mode with extensions turned off, then there are
probably quite a few that are very, very close. On the other hand, I
imaging that proving a compiler is perfectly strictly conforming is a
Turing problem.

But there are lint tools that are quite likely better than just about
any compiler's most conforming mode.
 
W

Walter Roberson

:On the other hand, I
:imaging that proving a compiler is perfectly strictly conforming is a
:Turing problem.

In theory it isn't an instance of the Halting Problem --
the Halting Problem has to do with the analysis of arbitrary
programs of arbitrary size. Turing's theorem is not that you
cannot prove the haltability of fixed individual programs, but
rather that there is no program which can be applied to
analyze -every- program.

But it would probably be difficult anyhow.
 

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

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,900
Latest member
Nell636132

Latest Threads

Top