CBFalconer said:
Once you have std::cout in func.c it is no longer C source. Now
you are dealing with something else entirely.
Well, of course. The whole module is C++; extern "C" is a C++ feature,
not a C feature. func.c is C++ source code from beginning to end. It
describes, in C++ code, a function that must be translated in such a way
as to be callable from C, but that doesn't make it C code.
I would prefer not to repeat myself, but you didn't address my previous
comments. When you said that func.h is a C routine, what precisely did
you mean? Were you actually referring to the function func(), or did you
in fact mean the header file func.h? If you were talking about func(),
how do you reconcile that statement with your current recognition that
the body of the definition of func() contains C++ source code?
What we are worrying
about is object modules (compiled code) that can be used in C and
in C++ programs. Valid programs.
>
I maintain that you can't have such modules written in C++ and
callable from C. Well, maybe I should cavil a bit, and say useful
modules. But you can have useful C modules callable from C++.
A C++ function written to be callable from C, can, when called from C,
do anything that any other C++ function can do. In what way do such
functions fall short of being useful? Or are you denying that this is
the case? Would you care to identify any particular feature of C++ that
you believe can't be used by such a function? Keith has already
demonstrated that there are at least two C++-specific features that can
be used in such a function.
You've talked repeatedly about modules. Neither the C standard nor the
C++ standard uses that term, but the usual meaning as I understand it is
that one object code module is created by the typical compiler as a
result of translating a single translation unit. Therefore, from your
wording I get the impression that you think this is controlled at the
translation unit level. Language linkage is controlled at the function
level, not the translation unit level. A single C++ translation unit can
contain functions with "C" language linkage and functions with "C++"
language linkage (and as many other language linkages as the compiler
cares to support, such as "Fortran" or "Pascal").