Richard Heathfield said:
James Harris said: [...]
This seems to me (yes, my opinion if you like) on
its own to directly outweigh the 'disadvantage' of the extra typing.
However, that's a side point. The main query is whether a community-
provided function can be distributed such that the above #include
would be valid whether telling the compiler to use ansi compatibility
or not.
An implementation is permitted to provide extensions provided they don't
break any strictly conforming program - that is, those extensions (the
ones that don't break strictly conforming programs) can be provided even
in conforming mode.
Right. To expand on that:
Suppose, for example, that a hypothetical compiler called xyzcc
provides ggets and fggets. (We will ignore any possible problems with
those functions (well, a macro and a function, but we'll ignore that
too).) It happens that ggets and fggets are implemented in portable
C, but that's beside the point.
Suppose that xyzcc provides the declarations of ggets and fggets in a
separate implementation-defined header, <ggets.h>. Then consider the
following program:
#include <stdlib.h>
#include <stdio.h>
#include <ggets.h>
int main(void)
{
char *line;
ggets(&line);
puts(line);
free(line);
return 0;
}
Strictly speaking, ``#include <ggets.h>'' causes the program to
exhibit undefined behavior (by omission, since the standard does not
define the behavior of any program with ``#include <ggets.h>''). For
all we know *based only on the standard*, <ggets.h> could contain code
that makes demons fly out of your nose. But the include directive is
neither a syntax error nor a constraint violation, so no diagnostic is
required. (Another implementation might reject the translation unit
with a diagnostic, perhaps because <ggets.h> doesn't exist.)
Similarly, the behavior of the statement ``ggets(&line);'' is not
defined by the standard. More precisely, the standard says that it
calls a function named ``ggets'' with the address of ``line'' as the
single argument, but it doesn't say how the function ``ggets'' itself
behaves. But again, there is no syntax error or constraint violation,
so no diagnostic is required.
An implementation *could*, in some super-strict mode, issue a
diagnostic warning that the use of <ggets.h> is non-portable, but this
is not required or even encouraged by the standard. As a practical
matter, anyone who's sufficiently familiar with the language will
already know that <ggets.h> is non-standard. (On the other hand,
someone who's not sufficiently familiar with the language might not
know this -- and someone trying to assess the portability of a large
body of code may not be able to find such non-portable constructs very
easily.) A compiler that accepts only truly portable C code, or at
least warns about anything that's not truly portable, would be a nice
thing to have, but the standard doesn't require it.
So the implementation is allowed to compile the above translation unit
without issuing any diagnostics. Furthermore, it's free to define the
behavior of any construct that's not defined by the standard itself.
On top of that, since no strictly conforming program can use
<ggets.h>, this extension cannot affect the behavior of any strictly
conforming program.