开发者

Why it compiles whether or not "extern" is used?

In a.cpp:

int t(开发者_StackOverflow)
{
  //definition goes here
  ...
}

b.cpp:

#include "a.h"

int main()
{
  t();
}

finally a.h:

extern int t();
//int t();

Both forms of a.h works,why?


Because function are extern by default, so the extern keyword is redundant. Some people like to explicitly add the extern when they want to hint other developers that the definition of the function are not to be found in the .cpp file with same name than this .h file, then they add a comment to point where the function is declared. But to the compiler's perspective, it does not affect anything.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜