extern "C" nests suspiciously

P

Phlip

Language Lawyers:

Compare this:

extern "C" int Maine()
{
...
bool runTests();
return !runTests();
}

to this:

bool runTests();

extern "C" int Maine()
{
...
return !runTests();
}

The first does not link because the true runTests() is not extern "C". But I
didn't specify extern "C" directly on bool runTests().

Should the extern "C" have been "inherited" from the enclosing function like
that?

Just curious. (But always glad to find yet another bug in Visual C++ 6!)
 
V

Victor Bazarov

Phlip said:
Language Lawyers:

Compare this:

extern "C" int Maine()
{
...
bool runTests();
return !runTests();
}

to this:

bool runTests();

extern "C" int Maine()
{
...
return !runTests();
}

The first does not link because the true runTests() is not extern "C". But I
didn't specify extern "C" directly on bool runTests().

Should the extern "C" have been "inherited" from the enclosing function like
that?

According to the Standard, language linkage specifications do nest. Every
declaration of a function inside another function will have the same
language linkage specification as the outside function. You can test your
compiler with
------------------------
extern "C++" void foo();

extern "C" void bar() {
void foo();
return foo(); // should give an error
}
------------------------
If your compiler throws a fit, you got a decent one (WRT language linkage
specifications, anyway).
Just curious. (But always glad to find yet another bug in Visual C++ 6!)

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,297
Messages
2,571,536
Members
48,282
Latest member
Xyprime

Latest Threads

Top