using extern template (C++11) to avoid instantiation

You should only use extern template to force the compiler to not instantiate a template when you know that it will be instantiated somewhere else. It is used to reduce compile time and object file size. For example: // header.h template<typename T> void ReallyBigFunction() { // Body } // source1.cpp #include “header.h” void something1() { … Read more

Should functions be made “extern” in header files?

From The C Book: If a declaration contains the extern storage class specifier, or is the declaration of a function with no storage class specifier (or both), then: If there is already a visible declaration of that identifier with file scope, the resulting linkage is the same as that of the visible declaration; otherwise the … Read more

What does the extern keyword mean?

extern gives a name external linkage. This means that the object or function is accessible through this name from other translation units in the program. For functions, this is the default linkage in any case so its usage (in this context) is usually redundant.

Does a declaration using “auto” match an extern declaration that uses a concrete type specifier?

There’s surprisingly little in the standard about this. About all we hear about redeclaration is: [C++11: 3.1/1]: A declaration (Clause 7) may introduce one or more names into a translation unit or redeclare names introduced by previous declarations. [..] and the only relevant part of auto‘s semantics: [C++11: 7.1.6.4/3]: Otherwise, the type of the variable … Read more

Mixing extern and const

Yes, you can use them together. And yes, it should exactly match the declaration in the translation unit it’s actually declared in. Unless of course you are participating in the Underhanded C Programming Contest 🙂 The usual pattern is: file.h: extern const int a_global_var; file.c: #include “file.h” const int a_global_var = /* some const expression … Read more

How does extern work in C#?

Consider reading section 10.6.7 of the C# specification, which answers many of your questions. I reproduce part of it here for your convenience: When a method declaration includes an extern modifier, that method is said to be an external method. External methods are implemented externally, typically using a language other than C#. Because an external … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)