[OpenIndiana-discuss] weird C++ problem

Bob Friesenhahn bfriesen at simple.dallas.tx.us
Mon Apr 1 19:49:34 UTC 2013


On Mon, 1 Apr 2013, James Carlson wrote:

> On 04/01/13 14:29, Apostolos Syropoulos wrote:
>> Hello everybody,
>>
>> I was trying to compile a program and one file failed to compile
>> with g++ 4.7.2 but it compiles with CC: Sun C++ 5.12 SunOS_i386 2011/11/16.
>
> The real question here might be why Sun's compiler doesn't gag.
>
>> using namespace std;
>>     namespace KPS {
>>         extern "C" {
>>             #include <string.h> //it includes another header that eventually
>>         }                       // included this header.
>>     }
>
> I think that begs a bit of a question: why would you want to include any
> header file (even one in your own application) within a namespace {}
> block?  That sounds to me like an open invitation to hard-to-understand
> problems.

I have a project which has done this since 1998.  It has never caused 
a problem across many platforms and C++ compilers.  The reason to do 
so is to divert the globally-visible symbols into a private namespace 
where they don't cause harm and they may be privately used.  This 
helps with C symbols but not with macros.

The extra extern "C" might be causing a problem, and as others 
mentioned, including <cstring> includes the C string functions in the 
std namespace.

Bob
-- 
Bob Friesenhahn
bfriesen at simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/



More information about the OpenIndiana-discuss mailing list