Dec 4, 2013

[C++][NOTE] extern "C" linkage

According to §7.5¶7 in the standard : A declaration directly contained in a linkage-specification is treated as if it contains the extern specifier (§7.1.1) for the purpose of determining the linkage of the declared name and whether it is a definition.
extern "C" int x; //is just a declaration
extern "C" { int y; } //is a definition
There are two different forms of the extern "C" declaration:
  • extern "C" void run() 
  • extern "C" { … } with the declarations between the braces.
The following two declarations are equivalent:
extern "C" int foo;
extern "C" void bar();
and
extern "C" {
     extern int foo;
     extern void bar();
}
As there is no difference between an extern and a non-extern function declaration, this is no problem as long as you are not declaring any variables. Keep in mind that
extern "C" int foo;
and
extern "C" {
    int foo;
}
are not the same thing.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.