Why is this happening????
I have this:
pTicketId->TicketNum = (DWORD) atol (_aux_str);
where: _aux_str = char [17] with a value of "3964856790"
so .. when doing this typecast , I expect to get a number == 3964856790 for
pTicketId->TicketNum but instead i keep getting 2147483647!!!!!
why is this happening .. does have something to do with my IDE?
(im using vs2005 pro)
thanks a lot guys
From the MSDN:
You have an overflow, and you're getting LONG_MAX returned. Because 3964856790 can't be represented in a 32-bit signed integer.
Quote:In Visual C++ 2005, in the case of overflow with large positive integral values, atol returns LONG_MAX; in the case of overflow with large negative integral values, LONG_MIN is returned. In all out-of-range cases, errno is set to ERANGE.
You have an overflow, and you're getting LONG_MAX returned. Because 3964856790 can't be represented in a 32-bit signed integer.
2147483647 is the DWORD-equivalent of -1. So, atol is trying to tell you that it encountered an error while trying to convert your value.
I think Steve is right, you can store max. 2,147,483,657.
You might also consider to use strtol, which is a bit better in reporting errors.
I think Steve is right, you can store max. 2,147,483,657.
You might also consider to use strtol, which is a bit better in reporting errors.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement