This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: AIX and tolower()


>>>>> GCS  writes:

GCS> I think it is correct. Details are coming:
GCS> the file begins with #include <ctype.h> which holds the definition for tolower
GCS> as 'extern int tolower(int)'. Later, the source has a
GCS> #if defined AIX
GCS> #define abc() tolower()
GCS> #endif
GCS> etc.
GCS> Then it is used in a loop:
GCS> for(i=0;i<strlen(string);i++)
GCS> string[i]=abc(string[i]);

GCS> Do you see any bad thing in the above usage?

	Your example does not appear to use any C++ objects.  If "string"
is a C-like string and you want to invoke a function in the C library, you
need to declare the function extern "C"

extern "C" int tolower(int);

	If you write the program with the appropriate C++ objects which
can access ctype, then tolower is already provided as a method on that
object. 

GCS> Btw, the linker gets libstdc++ to link with. I could not force libc, as -lc and
GCS> -l/lib/libc.a gave me an error.

	GCC always links with the system libc automatically, unless you
tell it not to.  g++ always links with libstdc++ automatically.

	The compiler is mangling the invocation of tolower in your
original example because you told it tolower was a C++ function.  This is
not a G++ or libstdc++ problem, it is a C++ programming question.  When
you tell the compiler the correct information, the program will link
correctly. 

David


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]