[RESOLVED] 64 bit data type

hi gurus,
I have a 32 bit target. Which data type should I use for 64 bit arithmetic? Also the target may change to 64 bit in the future. I am using gcc 4.1.1 and I wont revert to a lower version.
kum
edit
i am only a c guy
[255 byte] By [kumaresh_ana] at [2007-11-20 8:23:28]
# 1 Re: [RESOLVED] 64 bit data type
Will long long work? what will be the sizeof(long long) in a 64 bit machine? What the standard tells about this?
kumaresh_ana at 2007-11-9 1:19:58 >
# 2 Re: [RESOLVED] 64 bit data type
Both long long as well as unsigned long long are supported by GCC 3.x as well as 4.x. For IA32 under GCC these types are 64-bit. However, I am unsure if these data types are guaranteed to be 64-bit for all GCC cross targets.

What is your target?

Sincerely, Chris.
dude_1967 at 2007-11-9 1:21:04 >
# 3 Re: [RESOLVED] 64 bit data type
Embedded processors. intel xscale and mips. But this may grow to a 64 bit machine in the future. Do I have a generic data type that can be used across all platforms? else should I use typedefs for each platform?

thanks,
kum
kumaresh_ana at 2007-11-9 1:22:00 >
# 4 Re: [RESOLVED] 64 bit data type
Do I have a generic data type that can be used across all platforms?
No. Unfortunately in the C and C++ language there is no platform-independent type.
else should I use typedefs for each platform?
Yes. You must define platform independent types for your embedded projects.

Make a single file called, for example, my_types.h in which you define things like UINT8, UINT16, UINT32, UINT64, INT8, INT16, INT32, INT64. Ensure for each of your targets that these data types have the number of bits as given in the naming of the data types.

Please note: It is still unclear if 64-bit integer support exists for your target. You must verify this for each target.

In the end, you have something like this:

#ifndef _MY_TYPES_2007_07_06_H_
#define _MY_TYPES_2007_07_06_H_

#if defined(__MIPS__)

typedef unsigned int UINT32;
typedef unsigned long long UINT64;

#elif defined(__V850__)

typedef unsigned int UINT32;
typedef unsigned long long UINT64;

#elif defined(__C16__)

typedef unsigned long int UINT32;
// Possibly no support for UINT64. There are various possibilities here.

#else

#error "Types not supported"

#endif

#endif // _MY_TYPES_2007_07_06_H_

Sincerely, Chris.
dude_1967 at 2007-11-9 1:23:07 >
# 5 Re: [RESOLVED] 64 bit data type
The size is no type is guaranteed to be 64 bits in C++.

Probably you would need to device your own 64 bit type - and work with it - but it may cause performance degradation. Other option could be to use typedefs and change appropriately, provide releases for each target changing accordingly with that release.

I don't think there is a solution where in you can use any native types and just do a build on the specific target to get it to work (the only way is putting in a UDT that mimics the types that you want).
exterminator at 2007-11-9 1:24:05 >
# 6 Re: [RESOLVED] 64 bit data type
thanks dude_1967 and exterminator ...
kumaresh_ana at 2007-11-9 1:25:08 >
# 7 Re: [RESOLVED] 64 bit data type
Maybe there is a compiler dependent type like int64 or __int64? You can typedef them to INT64 so you have to change only one line of code when using another compiler which names it different.
GNiewerth at 2007-11-9 1:26:04 >