AIX and tolower()
David Edelsohn
dje@watson.ibm.com
Mon Jun 10 07:38:00 GMT 2002
>>>>> 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
More information about the Gcc-help
mailing list