Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Sep 2002 01:33:26 -0400
From:      "Lyndon Griffin" <lyndon@bsd4us.org>
To:        freebsd-questions@freebsd.org
Subject:   C++ symbol mangling
Message-ID:  <20020930053326.18827.qmail@bsd4us.org>

next in thread | raw e-mail | index | archive | help
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 <ctype.h>
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020930053326.18827.qmail>