linkage

Do inline namespace variables have internal linkage? If not, why does the code below work?

柔情痞子 提交于 2019-12-08 16:53:22
问题 This question is directly related to this one. Consider the code: #include <iostream> inline namespace N1 { int x = 42; } int x = 10; int main() { extern int x; std::cout << x; // displays 10 } It displays 10 . If I remove the extern int x; declaration then we get an ambiguity compiler time error error: reference to 'x' is ambiguous Question: why does the code work with the extern int x declaration work, and why does it stop working when I remove it? Is it because inline namespace variables

Mixing declarations with extern, static and no storage specifier in global scope

天大地大妈咪最大 提交于 2019-12-08 13:59:43
问题 I have been investigating when it is possible to mix variables declared with extern , static and no storage specifier in global scope. The results have left me quite confused. This is what I found (each paragraph is a separate compilation unit): /* ok */ int x; int x; /* ok */ int f(); int f(); /* ok */ int x; extern int x; /* ok */ int f(); extern int f(); /* error: static declaration follows non-static declaration */ int x; static int x; /* ok (no warning) */ int f(); static int f(); /* ok

macports, cmake/make and 'dyld: Library not loaded'

不打扰是莪最后的温柔 提交于 2019-12-08 10:45:00
问题 I recently upgraded a library I use in a project of mine (glfw-devel) with macports and now my executable is dynamically link with lib/libglfw.3.dylib instead of opt/local/lib/libglfw.3.dylib which is the actual location of the lib so I get a dyld: Library not loaded error. I know how to fix this with install-names or with a simple copy. What I cannot understand, however, is why this happens suddenly after a simple upgrade. I haven't changed anything in my CMakeLists.txt (the most relevant

How do I resolve this Weblogic intermittent java.lang.LinkageError? What are the steps to understanding what it means and fix it?

不问归期 提交于 2019-12-08 06:56:52
问题 I have an intermittent linkage error thrown: (That's basically all the information I have) java.lang.LinkageError loader constraint violation: when resolving field 'service' of the class loader instance of java/net/FactoryURLClassLoader) of the referring class org/apache/axis/client/Stub, and the class loader (instance of weblogic/utils/classloaders/ChangeAwareClassLoader) for the field's resolved type, java/xml/rpc/Service, have different class objects for that type Or in a more readable way

How to make a function with C-linkage from template?

筅森魡賤 提交于 2019-12-07 04:50:17
问题 I may be a little late to know this standard statement, after seeing the SO answer: [C++11: 7.5/1] Two function types with different language linkages are distinct types even if they are otherwise identical. which means, given: void f1(); extern "C" void f2(); decltype(f1) is not the same as decltype(f2) A reason that I wasn't aware of it until now is that the major compilers (e.g. g++, clang, vc++...) don't respect this rule. See LIVE DEMO. But I believe most people (include me) will be

C++ 匿名namespace的作用以及它与static的区别

一笑奈何 提交于 2019-12-06 20:18:31
一、匿名namespace的作用 在C语言中,如果我们在多个tu(translation unit)中使用了同一个名字做为函数名或者全局变量名,则在链接阶段就会发生重定义错误,为了解决这个问题,我们可以在定义这些标识符(identifier)的时候加上static关键字修饰以限制它只在一个tu范围内可见。 C++继承了C语言中static关键字的这个用途,我们依旧可以使用static来避免多个tu中使用同一个标识符带来的重定义问题。此外C++还提供了另一种特有的方式,那就是匿名namespace:一个没有指定名字的namespace被称为一个匿名namespace;在一个tu中可以出现多个匿名namespace,并且相同层次的匿名namespace实际上被合成为同一个;出现在不同tu的匿名namespace中的相同标识符相互独立不会发生冲突,因此我们可以把那些只希望在同一个tu范围可见的全局标识符放入一个匿名namespace中,效果与前面加static相同。 二、匿名namespace与static的区别 一个全局标识符被static修饰后它的linkage变为internal linkage,这就是为什么不同tu中的相同标识符不会发生冲突的原因。 而匿名namespace却并不会改变在它内部定义的标识符的linkage,它用来避免名字冲突所采用的手段同C+

External, internal and no linkage or why this does not work?

不问归期 提交于 2019-12-06 17:04:22
问题 According to C standard: In the set of translation units and libraries that constitutes an entire program, each declaration of a particular identifier with external linkage denotes the same object or function. Within one translation unit, each declaration of an identifier with internal linkage denotes the same object or function. Each declaration of an identifier with no linkage denotes a unique entity. In my example we have three separate declarations with each identifier having a different

Explain about linkages(external/internal) in c++?

。_饼干妹妹 提交于 2019-12-06 11:51:57
问题 Explain about linkages(external/internal) in c++? How does linkage differ for a function,constant,inline function,template function ,class and template class 回答1: Can you clarify your question a bit? C++ linkage is a pretty big topic and giving a complete answer in an SO post is probably a bit more information than you're looking for (Litb may prove me wrong). Here is a link which provides a general overview of linkage: http://gaubuali.wordpress.com/linkage-in-c-and-c/ 回答2: http://www

Is it possible to overload functions with extern linkage?

我的未来我决定 提交于 2019-12-06 02:55:46
问题 I saw a strange code, in declaration of std::atexit: extern "C" int atexit( void (*func)() ); extern "C++" int atexit( void (*func)() ); // ... why are there two functions? I guess it's some kind of function overloading, but it seems obviously wrong. What's it? and why is it necessary? 回答1: The problem with your source This is cppreference being a little misleading. Declaring the same function twice with different storage-class-specifiers is illegal and causes a build failure. If you look at

extern and extern “C” for variables

≡放荡痞女 提交于 2019-12-06 02:29:48
问题 I'm writing a C++ shared library for a C program to use. However, I have a question about extern and extern "C" . Consider the following code My header file is like this: #ifdef __cplusplus extern "C" int global; extern "C" int addnumbers(int a, int b); #else extern int global; #endif This works perfectly fine; I just have to declare int global; in either my .cpp or my .c file. However, what I don't understand is: What is the difference between extern "C" and extern here? I tried commenting