Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Saturday, January 23, 2016

C++ Long Long INT - 64-bits does this limit use to 64-bit OS only?

C++ Long Long INT - 64-bits does this limit use to 64-bit OS only?


With use of a C++ Long Long int being 64-bits does this limit use of this program to execution to a 64-bit OS only or would this still handle a 64-bit value within execution on a 32-bit OS?

I have a program that I am passing a integer seed to random generator and using the seed as a key for starting position within random algorithm. I compiled my code with long long int and it compiles and runs with no problems however my system is running Windows 7 64-bit and I dont have a 32-bit system to test it out on. While this program will mainly be run on my 64-bit system the reason behind this question is to understand if long long int use is only for a 64-bit OS system or if 32-bit systems can handle 64-bit int's through say 2 or more clock cycles to handle 64-bits vs a 64-bit OS being able to handle it in less clock cycles etc? Maybe I am comparing apples to oranges with 64-bit int to 64-bit CPU/OS? Thinking that if able to be handled by 32-bit CPU/OS that it may be inefficient at 64-bit int's?

Answer by novice for C++ Long Long INT - 64-bits does this limit use to 64-bit OS only?


Short answer - No.

The terms 32-bit and 64-bit refer to the way a computer's processor, handles information. The 64-bit version of Windows handles large amounts of random access memory (RAM) more effectively than a 32-bit system.
If you have a long long int, it simply means that it takes up 64 bits in the memory.

Refer to What is the difference between a 32-bit and 64-bit processor? , for a complete understanding of the differences between 32 bit and 64 bit processors.

Also take a look at - https://en.wikipedia.org/wiki/64-bit_computing

Answer by Niek Nooijens for C++ Long Long INT - 64-bits does this limit use to 64-bit OS only?


The integer size in memmory is independent of the amount of bits a CPU uses. hoewever the length of an int can vary because that processor always tries to run at it's most efficient way so for an 32 bit processor an int will have a default size of 32-bits. using types like long long int or uint64 (unsigned integer of 64 bit) will guarantee the length of 64 bits across all processors. so it's good to keep that in mind.

Answer by Peter for C++ Long Long INT - 64-bits does this limit use to 64-bit OS only?


In short, no.

Using long long types does not limit your choice of operating system. If your compiler supports long long and targets a 32-bit operating system (or even a 16-bit operating system), then the compiler or library sorts out the details of how to support longer types.

Using long long types does limit you to compilers (and libraries) that support such a type, no matter what operating system you use. In C++, the 2011 standard introduced them, but some older compilers support long long types as an extension (e.g. because C did since 1999). So, compilers predating the 2011 standard may not support long long types.

Answer by kamilk for C++ Long Long INT - 64-bits does this limit use to 64-bit OS only?


You are worried if your program will run the same when you run it on a 32-bit machine. You shouldn't.

If it's compiled as a 32-bit application it will always run the same, it just won't use the features of 64-bit processors. So you might have guessed long long was fine with 32-bit compilers because otherwise you wouldn't be able to build your program.

If it's compiled as a 64-bit application, it will not run on 32-bit machines at all.

Answer by Sam Varshavchik for C++ Long Long INT - 64-bits does this limit use to 64-bit OS only?


long long int is not guaranteed to be a 64 bit integer. At least not by the C++ standard:

3.9.1 Fundamental types [basic.fundamental]

 ...  

2 There are five standard signed integer types : ?signed char?, ?short int?, ?int?, ?long int?, and ?long long int?. In this list, each type provides at least as much storage as those preceding it in the list. There may also be implementation-defined extended signed integer types. The standard and extended signed integer types are collectively called signed integer types. Plain ints have the natural size suggested by the architecture of the execution environment; the other signed integer types are provided to meet special needs.

In other words, the only guarantee you have is that a long long int will be at least as big as a long int. That's it.

Now, on most modern execution environments, a long long int is a 64 bit value, and this is true even on native 32-bit hardware platforms.

But, as far as the C++ standard goes, you have no guarantees whatsoever. So, you might find that on a particular 32-bit platform, a long int and a long long int are both 32 bit integer values. And this will be perfectly compliant with the C++ standard.

Answer by abhishek rathore for C++ Long Long INT - 64-bits does this limit use to 64-bit OS only?


No, instead it completely depend on the data models used by the OS and the compiler being used. In C++ since C99 the size of long long int is 64 bits. Infact, most of the Linux/Unix implementations define long as a 64 bit type but it is only 32 bit in Windows because they use different data models. Have a look at given 64 bit computing related to models.

Answer by Peter A. Schneider for C++ Long Long INT - 64-bits does this limit use to 64-bit OS only?


Edit: long long int always exists in a C++11 implementation, and it has at least 64 bits because the C standard in 5.2.4.2.1 (not the C++ standard) demands it (by defining a minimum value of LLONG_MAX). That means you should be fine. On 32 bit systems the library may be slow or not available though.


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.