Topic: extern "C" {...} and static functions
Author: Thomas David Rivers <rivers@dignus.com>
Date: Mon, 11 Feb 2002 21:33:19 GMT Raw View
In the following example:
extern "C" {
static int static_func(int i)
{
...
}
}
What is the linkage-specification applied to
`static_func'?
I've got examples here of some compilers that
will use C++ linkage for that, and some that
will use C linkage.
The standard seems to strongly imply that
extern "C" would be for non-internal functions,
which means that a static function declared in an
extern "C" linkage specification block would
retain C++ linkage.
Is that a correct interpretation?
(Of course, this only matters on implementations
where the C++ and C linkage were actually different.)
- Many thanks! -
- Dave Rivers -
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: nobody <nobody@localhost.ucar.edu>
Date: Tue, 12 Feb 2002 16:00:33 GMT Raw View
Thomas David Rivers <rivers@dignus.com> wrote:
> In the following example:
>
> extern "C" {
> static int static_func(int i)
> {
> ...
> }
> }
>
> What is the linkage-specification applied to
> `static_func'?
According to my reading of the standard, it is a
function with internal linkage and C langage linkage.
That is, the name is not visible in external
translation units, but it is called with C
language linkage. The language linkage does
matter, becaise the function can be called
externally through a pointer:
extern "C" void external_func(int(*pf)(int));
int main () { external_func(static_func); }
> I've got examples here of some compilers that
> will use C++ linkage for that, and some that
> will use C linkage.
Do the compilers that use C++ linkage for static_func
reject the code fragment above? If they are consistent,
they should, because the language linkage is part of a
function's type (and also that of a pointer to function).
> The standard seems to strongly imply that
> extern "C" would be for non-internal functions,
> which means that a static function declared in an
> extern "C" linkage specification block would
> retain C++ linkage.
>
> Is that a correct interpretation?
I don't think so. Here is a quote from clause 7.5:
In a linkage-specification, the specified language
linkage applies to the function types of all function
declarators, function names, and variable names
introduced by the declaration(s).
It says "all function names" not "all function names
except those referring to functions with internal
linkage".
nobody
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]