[Interest] string conversion to longlong error

Rogers Nate nate.rogers at raymondcorp.com
Wed Sep 3 18:11:58 CEST 2014


On 09/03/2014 11:53 AM, Calogero Mauceri wrote:
> Hi all,
>
> I'm doing something really simple, but which is driving me crazy.
>
> I'm reading a string from a file and converting it to a long long 
> integer, but the conversion fails.
> The code I'm running is as simple as this
>
>      // this string is read from a file
>      QString str("18446744073709551615");
>      bool ok;
>      qint64 value = str.toLongLong(&ok);    // Error
>
> the number should be representable in 64 bit. Am I doing something wrong?
>
> More hints, if I convert the number to unsigned long long integer then 
> it works
>
>       bool ok;
>       quint64 value = str.toULongLong(&ok);    // OK
>
> Similarly initializing the long long from the literal value is failing too
>
> Q_INT64_C(18446744073709551615) ;      // Error, returns -1
> Q_UINT64_C(18446744073709551615);    // OK
>
> Thanks for your help!
>      Calogero
>

18446744073709551615 is too big to fit into a long long.  It is actually the biggest number you can have a unsigned long long.  A long long can't fit the same size number because it has to use one bit to hold the sign.  The maximum number you can fit in a long long is 9223372036854775807.

Nate



Confidentiality Notice: The preceding e-mail message (including any attachments) contains information that may be confidential, protected by applicable legal privileges, or constitute non-public information. It is intended to be conveyed only to the designated recipient(s). If you are not an intended recipient of this message, please notify the sender by replying to this message and then delete it from your system. Use, dissemination, distribution or reproduction of this message by unintended recipients is not authorized and may be unlawful.




More information about the Interest mailing list