Warning with the use of tolower

A

asbisht

Greetings to everyone.

#include<iostream>

main( void )
{
unsigned char value = 'A';
std::cout << tolower(value);
return 0;
}

if I compile this using Solaris CC with +w option, then it gives me the
following warning:

Warning: Could not find source for std::tolower(int).

Please tell me why the above warning is coming and the idea to avoid
it.


Regards,
-Ajay
 
J

James Daughtry

You need to include <cctype> to use the single argument definition of
tolower. And don't forget to qualify it with std. Standard C++ also
disallows implicit int for function definitions:

#include<cctype>
#include<iostream>

int main( void )
{
unsigned char value = 'A';
std::cout << std::tolower(value);
return 0;
}
 
A

asbisht

Hi James,

I had tried that before but it couldn't remove that warning. Moreover,
I have also tried typecasting it as int (*)(int) but that also didn't
work. I'm attaching the transcript with your suggestion as follows:
 
L

Larry I Smith

Greetings to everyone.

#include<iostream>

main( void )
{
unsigned char value = 'A';
std::cout << tolower(value);
return 0;
}

if I compile this using Solaris CC with +w option, then it gives me the
following warning:

Warning: Could not find source for std::tolower(int).

Please tell me why the above warning is coming and the idea to avoid
it.


Regards,
-Ajay

The C++ versions of tolower, toupper, isalnum, etc
are in <locale>. These versions work with more
charsets than just ASCII.

#include <iostream>
#include <locale>

int main()
{
unsigned char value = 'A';
char lower = std::tolower(value);
std::cout << lower << std::endl;
return 0;
}

Regards,
Larry
 
P

Pete Becker

Larry said:
The C++ versions of tolower, toupper, isalnum, etc
are in <locale>. These versions work with more
charsets than just ASCII.

The C versions work with more charsets than just ASCII as well. Read
about setlocale.
 
L

Larry I Smith

Pete said:
The C versions work with more charsets than just ASCII as well. Read
about setlocale.

Did I say they didn't? :)

When using C++, we use the Std C++ features wherever possible.

e.g use

#include <locale>
 
P

Pete Becker

Larry said:
Did I say they didn't? :)

You obviously implied it.
When using C++, we use the Std C++ features wherever possible.

When using C++ we use the most appropriate coding technique, whether
it's labeled C, preprocessor, or whatever. Std C++ features aren't
autmoatically the best way to do something.
 
L

Larry I Smith

Pete said:
You obviously implied it.

I sure didn't mean to...
When using C++ we use the most appropriate coding technique, whether
it's labeled C, preprocessor, or whatever. Std C++ features aren't
autmoatically the best way to do something.

Well, OK. To each his own. :)

Larry
 
L

Larry I Smith

Pete said:
Being supercilious is not the same as being right.

It's not a matter of "being right", or wrong. It's
just a matter of choice. Both versions of tolower()
work just fine.

We use the Std C++ features primarily. That's just
the choice made by our corporate Engineering Council
and defined in our Coding Standards.

I really didn't mean to upset anyone over the simple
choice of using std::tolower() versus ::tolower().

Regards,
Larry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top