Bartc said:
Seems a 'well-defined subset of C99' is still a good idea.
I'll grant you that a "well-defined subset of C99" *would be* a good
idea. Though I'd be much happier if all the relevant implementers
just implemented the whole language, eliminating the need for subsets.
Note that the latter is essentially what happened for C90; you don't
see many C compilers that fail to implement all of the C90 standard.
The problem is that nobody has actually defined such a subset -- other
than C90 itself, of course (or rather, the intersection of C90 and
C99).
Which subset this should be is hard to tell from your example: there are 4
implementations of each feature apart from P.
And in the real world, where there are more than 6 C99-specific
features and more than 6 implementations, it's nearly *impossible* to
tell what this subset should be.
I would go with the easiest to implement and/or those which already exist
anyway. It might be there is already a subset implemented across many
compilers, for example //-comments and long-long-int. That would at least be
a start, and require little effort. Eg. the subset [P] in your example.
And how would you go about enforcing this?
Let's assume, for the sake of argument, that all C compilers implement
// comments and long long. (Note that the latter also requires
library support for the *printf and *scanf functions; the library
isn't necessarily provided by the same vendor as the compiler.)
But as far as I know, no compiler enforces that particular subset.
For example, gcc also implements mixed declarations and statements.
If I'm going to write code using a well-defined subset of C99, I want
my compiler to warn me when I violate that subset. If I tell gcc to
accept // comments and long long, it will *silently* accept mixed
declarations and statements as well, and when I try to port my code to
another compiler that supports this well-defined subset, it chokes
because the other compiler *doesn't* support mixed declarations and
statements.
A conforming C90 compiler or a conforming C99 compiler will diagnose
code that fails to conform to the specified standard. That's one of
the great advantages of having a standard. If there were widely
available conforming well-defined-subset-of-C99 compilers that
diagnosed code that fails to conform to that subset, we could use that
subset with some confidence. But there aren't -- *unless* the subset
you choose is just the intersection of C90 and C99. Even then you
could miss warnings for things like implicit int that are valid C90
but invalid C99, but there are few enough features that we can live
with that.
Now if you only care about implementations that support some certain
subset of C99 features, and you're willing to accept the risk that one
compiler won't diagnose code that goes beyond that subset, and you
therefore can't be sure of how portable your code is until you test it
on all relevant systems, then that's fine; go ahead and use whatever
C99 features you like. It may even be the case that most C
programmers are in a position to do so.
And for platforms for which there is only G, and there exists a good reason
to port your code to that platform, then the customers of that platform
should demand a [P]-compliant compiler. Otherwise why should G stifle the
development and progress of all the others?
Have you ever tried *demanding* that a vendor support some particular
feature?