Hi,
Is there any replacement for __int64 type with something which is OS independent? Do I need to include any file, or can do it with some typedef?
Thanks
3 3697
Can we do it using this - typedef long long int64_t?
Is there any good tutorial giving indepth explanation about the data types and their dependencies on compilers?
Thanks,
I have no idea why C/C++ compilers can't agree on sizes for the various int types. They keep playing the "less or equal to than" game, where char size is <= to short which is <= int etc., etc. I assume the C standard started all of this.
Many C/C++ compilers have informally standardized on char=8 bits, short=16, and int=32 in both the 32 and 64 bit systems.
With the 64 bit systems, long is now the unknown. Windows keeps long as 32 bits and linux upgraded long to 64 bits. I think long long is as close to an OS independent specification you'll find for a 64 bit int type.
Banfa 9,065
Expert Mod 8TB
For C99 you can include stdint.h which defines lots of fixed size, minimum size and fastest size types similar to int32_t, int16_t, int64_t.
For C/C++ compilers that are C99 compilant (ish) this file exists so you can often included it even if you are actually using C89 or C++ however that does effectively make your code non-portable (although it gives it a single point of failure).
The reason that the types where never given fixed sizes is because of the original basic definitions of char and int.
char is a type that can address every byte of memory contiguously, the standard guarantees this.
int is the type that is most efficient for the processor to handle. So for 8 bit processor 8 bits, for 16 bit processors 16 bits and for 32 bit processors 32 bits.
The problems have arrisen because although the sizes of char, short, int and long are not fixed programmers programmed as though they were.
So in order to stop things breaking everywhere when PC processors jumped to 64 bit they didn't change the size of the various types even though from a standard point of view they probably should have done.
What windows has done with long on 64 bit machines is a little silly as there is now no standard built in integer type for C89 on Windows with 64 bits. I think the Linux approach makes more sense. But that is personal opinion.
What is important is that size of int is left to float to the most appropriate value for the platform.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Matt Whelan |
last post by:
Supposedly, recent versions of SWIG can be made to work with MS VC++'s
non-standard integer data types. According to a recent SWIG ChangeLog
entry:
%apply long long { __int64 };
should make...
|
by: JR |
last post by:
Take a look at TestStruct1 and TestStruct2. Clearly, the D2 part of
the union is MUCH larger than the D1 portion. I would expect
sizeof(TestStruct1)==sizeof(TestStruct2) but that is not the case...
|
by: Jesse Hose |
last post by:
I get odd behavior in the debugger with the following code. The output of
the program itself is correct, but when I add the g_bad_int64_max and
g_bad_int64_min to the watch window they show values...
|
by: Jayesh |
last post by:
Hi,
How is a double value stored in 8 bytes ? Or what is the format ?
How is it different from __int64 ? How is __int64 stored in 8 bytes.
Please do reply.
regards,
Jayesh
|
by: hurry |
last post by:
hi,
I am writing a c program in VC++ 6.
I have 2 files with 3 functions.
file-1 having two functions "a" and "c"
file-2 having a single function "b"
with function "a" as main() , "a"...
|
by: Whybother |
last post by:
I have this
typedef map<__int64, int> Results_Map;
__int64 is defined as 8 bytes ranging from -9,223,372,036.854,775,808 to
9,223,372,036.854,775,807
I have loaded it with approx 34 million...
|
by: kgpsoftware |
last post by:
Hi folks,
I have a DLL which contains functions that return __int64 values, but I
can't get Visual C to read the return value correctly. I am using the
2003 version.
Here is the declare:
...
|
by: Angus |
last post by:
I need to convert a double to a 64 bit integer. I am using __int64
but could of course use a more portable type.
To perform the correct casts:
double d = 3.3;
__int64 i64;
i64 =...
|
by: Kenzogio |
last post by:
Hi,
I have a struct "allmsg" and him member :
unsigned char card_number; //16
allmsg.card_number
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |