Click here to Skip to main content
15,881,769 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Is it safe to use long long data type in a win32 windows OS?

I am using sqlite datatabase for a certain app. I noticed that the INTEGER PRIMARY KEY AUTO INCREMENT data type is of data type long long ( but typedefed in sqlite).

I also noticed that the long long data type is 64 bit in size.

Is it really safe and proper to use this data type for an app that is meant for a 32 bit OS?
Posted
Updated 11-Dec-14 1:28am
v2
Comments
CPallini 12-Dec-14 7:48am    
Yes, of course.

yes it is shure, but check that the 64-bits are at all times preserved. No casts and no signed / unsigend mismatch.

I would use a own typedef datatype to make it obvious.

typedef MY_KEY_TYPE unsigned __int64
 
Share this answer
 
In principle, there's no restriction to the datatype size, regardless of the OS, or for that matter, the CPU. When building the program, the compiler handles the way the math is done. If you've a 32-bit cpu, you can still do 64-bit arithmetic. It's just not efficient.

Better put: a cpu is most efficient on the data type for which it is designed: it has registers of the appropriate size and mathematical operations between these registers (more-or-less) directly. A 32 bit system will do, for example, a 64-bit add, but it will take multiple steps (high-order and low order addition and taking care of any "carry over"). When defining data types, INT will be defined as the native size for the targeted O/S. A SHORT is at least 16bit, a LONG, at least 32, etc., but an INT depends . . !

Most current CPU's are 64-bit. A matching OS type means it will run more efficiently (faster).

It is important, however, that you never mix double-long ints with others when doing any operations: if you do, there will be truncation errors and these are irrecoverable once they are applied to your data. Overflows are another possibility. This rule always applies! Not just for double-longs!
 
Share this answer
 
v2
Comments
Orjan Westin 12-Dec-14 4:49am    
No, a short is never bigger than an int and never smaller than a char, and a long is never smaller than an int. That's all the language specifies. On 16-bit architectures (showing my age here) short was often 8 bits.
W Balboos, GHB 12-Dec-14 7:35am    
I had a whole story for a comment, but I made changes, above, to reflect the parts of what you say which are correct. For a normal compilation, the INT type is designed to match that of the platform (a reason to have different versions for Win32 vs Win64). Coding with INT (rather than short, long, etc.) will potentially improve the speed of execution.

On my first platform shorts and integers were both 16-bit. As a newbie, I always wondered what that was all about.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900