Andrew Pinski <pins...@gmail.com> writes: | On Wed, Apr 27, 2011 at 6:30 PM, Gabriel Dos Reis <g...@cs.tamu.edu> wrote: | > | > Richard, | > | > Your recent patch broke --enable-build-with-cxx because internal-fn.h | > was using good 'ol C-style name lookup trick that behaves badly with | > C++ linkage rules. Fixed thusly. Applied as obvious. | | Can you explain some more? Does it have do with the fact those | functions are static?
The issue has nothing to do with the fact that the functions are static. A local `extern' declaration does not give the entity an external linkage -- irrespective of the linkage of the function enclosing the declaration. It just makes the name locally available for name lookup purpose. A variable declared const has -- external linkage by default in C -- internal linkage by default in C++ So before the patch: the variables had external linkage in C, but internal linkage in C++. That meant that a link will fail in C++, but succeeds in C. All my patch did was to give the external linkage explicitly (both in C and in C++.) | If so I think we should move away from static | functions for compiling with C++ and move to using anonymous | namespaces. I suspect that is a separate issue. BTW, in my own codes I still use "static" for non-member functions because the compiler will tell me when a function becomes unused. GCC at the moment is unable to tell when a function in an unnamed namespace is unused (that is surely a bug.) For that reason alone, I would recommend that we keep "static" for functions. -- Gaby