The C standard specifies exactly and completely all of the names
that each header defines; a conformant implementation cannot
define any others in the header (except in the reserved
namespace, i.e. names starting with a _).
C++ allows any standard header to include any other, so you may
get more names than those defined in the header you include.
But still limited to names defined by the standard in one of the
standard headers (or names in the reserved namespace, of
course).
I assume that by posix you mean those posix headers that are not C
headers and similarly for C++ you exclude *.h and c*.
No. I mean all Posix headers. Except, of course, those names
that are common to both C and Posix: if you include <stdio.h>,
you get printf, and on an X/Open system, a printf with the
X/Open extensions (which is still standard C, since the X/Open
extensions define what is otherwise undefined behavior).
There are a very few incompatibilities between some of the Posix
headers and the C standard. Posix recognizes this, and
(IIRC) specifies that by default you get standard C; you have to
explicitly define a preprocessor symbol to get Posix. And even
then you only get these few incompatibilities; you don't pull in
any other Posix headers.
C++ headers can (and do, on unix systems) include posix headers.
If they do, it's a very, very poor implementation. There's no
reason to.
New
C++0X features like threads will make that even more obvious.
Why?
As for the reverse direction, it is indeed probably rare, but
I don't think it is forbidden.
I don't think Posix forbids including other Posix and C headers.
Like C and C++, however, it does forbid introducing additional
symbols, not defined in Posix (or C, since Posix includes the C
standard by reference), in a Posix header.
Note that the guarantees given by the C and the C++ standards go
even further: if your code contains symbols which are defined by
Posix, and you don't include Posix headers, your code must link
correctly, and use your code, e.g.:
#include <stdio.h>
int
read(int fd, char* buf, size_t len)
{
puts(buf);
}
int
main()
{
static char hello[]= "hello, world!";
read(0, hello, 0);
char ch = getchar();
return 0;
}
must compile, link and output "hello, world!" when executed.
(Back in the 1980's, it didn't always. But that was then; I
can't imagine a system today where this didn't work.)