Sign in to follow this  
asdqwe

impossible w/o casting

Recommended Posts

I've heard casts have to be avoided as much as possible, and can always be avoided. But SOME functions seem to require them. EG:
void main()
{
		int nr;
		nr = strlen("Babe Ruth");
		cout<< nr;
}
That way, I get: warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data. But when I change the offender into:
size_t nr;
I get: warning C4267: 'argument' : conversion from 'size_t' to 'unsigned int', possible loss of data. So I'm asking: Can anyone, including Bill Gates, fix this so it doesn't spit warnings OR require typecasts?

Share this post


Link to post
Share on other sites
Quote:
Original post by asdqwe
But when I change the offender into:
size_t nr;
I get: warning C4267: 'argument' : conversion from 'size_t' to 'unsigned int', possible loss of data.
So I'm asking: Can anyone, including Bill Gates, fix this so it doesn't spit warnings OR require typecasts?

My compiler doesn’t give any error or warning using size_t in your code.

Share this post


Link to post
Share on other sites
To nife87: your code still is buggy. Now I get a warning on the std::cout line: warning C4267: 'argument' : conversion from 'size_t' to 'unsigned int', possible loss of data
So it's no good!

Share this post


Link to post
Share on other sites
It sounds like you have the /Wp64 flag enabled for your project. Using this flag gives a lot of spurious warnings. Go to your project settings and disable "Detect 64-bit Portability Issues" in the C++/General section.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this