R
Robert Fendt
Hi,
I just came across something very odd. In an old project, there were
declarations of the scheme
extern "C" void foo(int&);
thus using C++ reference types in a C-linkage declaration. In the C++
implementation used (VC++), the binary code produced is apparently
identical to foo(int*), a fact that is actually used in the project I
mentioned, i.e. a second header file(!) exists declaring the pointer
version:
#ifdef __cplusplus
extern "C" {
#endif
void foo(int*);
#ifdef __cplusplus
}
#endif
I am very surprised that the compiler even allows a reference type in
an 'extern "C"' block. Apparently the standard does not disallow C++-
specific types in C-linkage declarations (at least I did not find
anything), but: how much sense does this make? Is a reference type in
the argument list guaranteed to 'collapse' to a pointer, or is this
just a happy coincidence. I cannot help but feel that this is quite an
ugly example of perverting knowledge of implementation details...
Regards,
Robert
I just came across something very odd. In an old project, there were
declarations of the scheme
extern "C" void foo(int&);
thus using C++ reference types in a C-linkage declaration. In the C++
implementation used (VC++), the binary code produced is apparently
identical to foo(int*), a fact that is actually used in the project I
mentioned, i.e. a second header file(!) exists declaring the pointer
version:
#ifdef __cplusplus
extern "C" {
#endif
void foo(int*);
#ifdef __cplusplus
}
#endif
I am very surprised that the compiler even allows a reference type in
an 'extern "C"' block. Apparently the standard does not disallow C++-
specific types in C-linkage declarations (at least I did not find
anything), but: how much sense does this make? Is a reference type in
the argument list guaranteed to 'collapse' to a pointer, or is this
just a happy coincidence. I cannot help but feel that this is quite an
ugly example of perverting knowledge of implementation details...
Regards,
Robert