devxlogo

The Linkage Type of Typedef Names

The Linkage Type of Typedef Names

By default, a typedef name declared in the global scope has internal linkage. This means that separately compiled source files can’t refer to a typedef declared in another source file, unless that typedef is explicitly declared “extern.” In this respect, C++ is different from C, which make typedef names global by default. Thus, in C++ you are allowed to define the same typedef name in every separately compiled source file as long as the definitions are identical:

 // file first.cpp  typedef int I; // visible only in the scope of this file  void func(I);// file second.cpp  typedef int I; // visible only in the scope of this file  float func2(I);

devx-admin

Share the Post: