Our website uses cookies to enhance your browsing experience.
Accept
to the top
close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

close form
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam

Webinar: Evaluation - 05.12

>
>
>
How to correctly print a value of the t…

How to correctly print a value of the types __int64, size_t, and ptrdiff_t

Feb 04 2013
Author:

When developing an application, you may often face a trouble that variables of the types __int64, size_t, or ptrdiff_t are printed incorrectly. First of all we should mention the difference between these data types. The __int64 type, for instance, always has the size 64 bits both on the 32-bit and 64-bit platforms. The types size_t and ptrdiff_t are 32-bit on the 32-bit platform and 64-bit on the 64-bit platform. It is this point that causes troubles and confusion when printing values of these types.

There are two ways to eliminate the problem:

1. Using safe methods

For example, you can replace printf with cout, and sprintf with boost::format or std::stringstream.

2. Using a correct format string

a) For the __int64 type, regardless of the compiler (C++Builder, MSVC, or GCC):

printf("%lld", i);

b) For the types size_t and ptrdiff_t:

k0046_How_to_print__int64/image1.png

References

Popular related articles


Comments (0)

Next comments next comments
close comment form