[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
# 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.
# 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).