[ http://issues.apache.org/jira/browse/XERCESC-1331?page=comments#action_58429 ] Robert Buck commented on XERCESC-1331: --------------------------------------
I'll let others defend the idiom: >From Bjarne Stroustrup: "The use of static to indicate 'local to translation unit' is deprecated in C++. Use unnamed NameSpaces instead." [Bjarne Stroustrup, The C++ Programming Language, 3rd ed, pg 819] "In C and older C++ programs, the keyword static is (confusingly) used to mean 'use internal linkage' Don't use static except inside functions and classes." [Bjarne Stroustrup, The C++ Programming Language, 3rd ed, pg 200] >From IBM: "Items defined in an unnamed namespace have internal linkage. Rather than using the keyword static to define items with internal linkage, define them in an unnamed namespace instead." >From Microsoft: "Unnamed namespaces are a superior replacement for the static declaration of variables. They allow variables and functions to be visible within an entire translation unit, yet not visible externally. Although entities in an unnamed namespace might have external linkage, they are effectively qualified by a name unique to their translation unit and therefore can never be seen from any other translation unit." [MSDN Online] Lastly, and most importantly, from the C++ Standard itself: "The use of the static keyword is deprecated when declaring objects in a namespace scope (see annex D); the unnamed-namespace provides a superior alternative." [Programming languages — C++, ISO/IEC 14882:2003(E)] > Globals intended for use in a single file should be static > ---------------------------------------------------------- > > Key: XERCESC-1331 > URL: http://issues.apache.org/jira/browse/XERCESC-1331 > Project: Xerces-C++ > Type: Bug > Versions: 2.5.0, 2.6.0 > Environment: Win32, Visual Studio .NET 2003, static library > Reporter: Jesse Pelton > Priority: Minor > > util/NetAccessors/WinSock/BinHTTPURLInputStream.cpp declares and uses several > global variables. These variables do not appear to be intended to be visible > outside the module. If this is the case, they should be declared static. > I bumped into this when trying to build the Apache XML Security code with a) > Xerces namespace support disabled and b) a statically linked Xerces library. > XML Security has a modified version of the BinHTTPURLInputStream class, > including copies of the offending globals. This results in warnings from the > linker when it detects that the globals are multiply defined. They should > fix their end, too (I'll file a report there, too), but the Xerces code > should correctly declare its intent as well. > Changing util/NetAccessors/WinSock/BinHTTPURLInputStream.cpp is simple. The > following lines need "static " inserted at the beginning: > HMODULE gWinsockLib = NULL; > LPFN_GETHOSTBYNAME gWSgethostbyname = NULL; > LPFN_INET_ADDR gWSinet_addr = NULL; > LPFN_GETHOSTBYADDR gWSgethostbyaddr = NULL; > LPFN_HTONS gWShtons = NULL; > LPFN_SOCKET gWSsocket = NULL; > LPFN_CONNECT gWSconnect = NULL; > LPFN_SEND gWSsend = NULL; > LPFN_RECV gWSrecv = NULL; > LPFN_SHUTDOWN gWSshutdown = NULL; > LPFN_CLOSESOCKET gWSclosesocket = NULL; > LPFN_WSACLEANUP gWSACleanup = NULL; > The result: > static HMODULE gWinsockLib = NULL; > static LPFN_GETHOSTBYNAME gWSgethostbyname = NULL; > static LPFN_INET_ADDR gWSinet_addr = NULL; > static LPFN_GETHOSTBYADDR gWSgethostbyaddr = NULL; > static LPFN_HTONS gWShtons = NULL; > static LPFN_SOCKET gWSsocket = NULL; > static LPFN_CONNECT gWSconnect = NULL; > static LPFN_SEND gWSsend = NULL; > static LPFN_RECV gWSrecv = NULL; > static LPFN_SHUTDOWN gWSshutdown = NULL; > static LPFN_CLOSESOCKET gWSclosesocket = NULL; > static LPFN_WSACLEANUP gWSACleanup = NULL; -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]