From owner-freebsd-questions Sun Sep 29 22:33:30 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5F34637B401 for ; Sun, 29 Sep 2002 22:33:28 -0700 (PDT) Received: from bsd4us.org (dsl-65-174-220-210.dslx.net [65.174.220.210]) by mx1.FreeBSD.org (Postfix) with SMTP id 7537C43E3B for ; Sun, 29 Sep 2002 22:33:27 -0700 (PDT) (envelope-from lyndon@gemini.bsd4us.org) Received: (qmail 18828 invoked by uid 1000); 30 Sep 2002 05:33:26 -0000 Message-ID: <20020930053326.18827.qmail@bsd4us.org> From: "Lyndon Griffin" To: freebsd-questions@freebsd.org Subject: C++ symbol mangling Date: Mon, 30 Sep 2002 01:33:26 -0400 Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG I'm involved in a porting project. I say that first because changing the code that I will list below is less of an option than it may seem. It's part of an API that third-party developers code to, my work on porting comes in secondary to changing the API. The code compiles as is, not even a warning, on win32 and linux. The environment is 4.6-STABLE, maybe a few weeks outta date, using the default GCC toolchain (2.95.3). Here's the code (well, a relevant representation, anyways). The example below is sufficient to reproduce the problem, at least. ------MyString.h------ class MyString { public: MyString(){}; ~MyString(){}; void toupper( void ); void tolower( void ); static char * toupper( char * ); static char * tolower( char * ); }; ------MyString.cpp----- #include "MyString.h" #include char * MyString::toupper( char *s ) { char *t = s; while ( *t ) { *t = ::toupper( *t ); t++; } return ( s ); } char * MyString::tolower( char *s ) { char *t = s; while ( *t ) { *t = ::tolower( *t ); t++; } return ( s ); } Seems harmless enough, when looking at it... The trouble is that the preprocessor is changing the name of MyString::toupper() to MyString::__toupper (same for tolower), which is, of course, not declared in the class. This feels like the result of the compiler getting confused between the definition of toupper in ctype.h *and* in this program's source. The questions: 1) Are the ctype.h definitions getting in the way? 2) Is there a compiler flag to prevent this behavior? If so, what is it? 3) Barring the compiler flag, could someone architect for me a macro or two that would prevent this problem? Thanks mucho, <:) Lyndon http://bsd4us.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message