Long long and __int64 usage summary

Source: Internet
Author: User

This digest is from the Web. Original URL: http://blog.sina.com.cn/s/blog_6aa178410100vlwr.html

Objective:
In 16-bit environments, int/unsigned int accounted for 16 bits, long/unsigned long accounted for 32 bits
In 32-bit environments, int accounted for 32 bits, unsigned int accounted for 16 bits, long/unsigned long accounted for 32 bits
When to use:
The long and int ranges are [ -2^31,2^31], which is -2147483648~2147483647, and the unsigned range is [0,2^32], which is 0~4294967295, so the regular 32-bit integer can only handle about 4 billion, When it comes to a number larger than 4 billion, it's going to take 64 bits.
64-bit Use range:
Different compilers differ on 64-bit integers, vcs use __int64/unsigned __int64, range is [ -2^63, 2^63) and [0,2^64], which is -9223372036854775808~ 9223372036854775807 with 0~18446744073709551615 (about 180 billion).
Note the point:
1, the compiler different results in the use of 64-bit declaration method is different;
2, long long/unsigned long long is generally under the Linux declaration method, such as: g++
3, __int64/unsigned __int64 is generally used under Windows 64-bit declaration method, such as: VS
4, in the assignment need attention plus ll for explicit assignment;
5, when the 64-bit and 32-bit mixed operation, 32-bit integers are implicitly converted to 64-bit integers.
6, Output printf (""), long long using%LLD output, __int64 using%i64d, unsigned use u instead of D.
7, test down the compiler generally support 2 kinds of operations, not too tangled, how to use to see personal likes.

================================= Gorgeous divider Line ========================================

1#include <stdio.h>2#include <stdlib.h>3 int main () {4UnsignedLongLong a=412432424000LL;5unsigned __int64 b=9223372036854775808ll;6printf"%i64u\n", a);//unable to output properly when using%lld, why?7printf"%i64u", b);8System"Pause");9     return 0;Ten}

Test results of the attached netizens:
Just experiment, in VC6, DEV, codeblocks C language can use __int64, formatted output is identified as%i64d. However, in the VC6 after the number plus 2 L will be an error, you can add only 1 or no Add. Check the information, __int64 is dedicated to Windows, by the VC, GCC and other compilers support, but in Unix, Linux needs long long with%LLD. The latter is standard C of the provisions!
I tried the next long long match%i64d, can be correctly output, and whether it is a long long or __int64 with%LLD can not be correctly output. So I came to the conclusion that I need a long long or __int64 with DD under Windows. And in Unix, Linux must use the standard C provisions of long long with%LLD.

Long long and __int64 usage summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.