Data types ranges and size
Hi,
I have one question regarding data types. I'm using Visual DSP v4.0 for ADSP21364.
The compiler manual says : "On any platform, the basic type int is the native word size. For SHARC processors, it is 32 bits."
Then there is a table where the bit size of each data type is shown. According to that table all data types are 32 bit-long.
My first question is: the bit size is not the range, is it? I mean a variable of type "char" ranges from -127 to 128 (8bits) but its size in memory is 32 bit.
My second question is: which is the range of a variable of type "int"? And a variable of type "long int"? And a variable of type "short"? They are all 32 bit long in memory but not in range, is this right?
Thanks
imanol
ranges
data
types
Hi,
take a look at the "limits.h" header file, which defines the ranges for integral data types. This can be found at "...\213xx\include\limits.h".
Regards,
Craig.
Hi Imanol,
Correct, they all have the same range (so all signed integrals have the same range, and all unsigned integrals have the same range), as they all have 32-bit data size.
Did you encounter any errors or issues when trying to do your typedefs in your own data_types.h?
Regards,
Craig.
Hi,
According to limits.h all integral data types have the same range. So there is no difference between declaring a "char" and an "int"?
#define CHAR_BIT 32
#define SCHAR_MIN (-2147483647 -1)
#define SCHAR_MAX 2147483647
#define UCHAR_MAX 4294967295u
#define CHAR_MIN SCHAR_MIN
#define CHAR_MAX SCHAR_MAX
#define MB_LEN_MAX 1
#define SHRT_MIN SCHAR_MIN
#define SHRT_MAX SCHAR_MAX
#define USHRT_MAX UCHAR_MAX
#define INT_MIN SHRT_MIN
#define INT_MAX SHRT_MAX
#define UINT_MAX USHRT_MAX
#define LONG_MIN INT_MIN
#define LONG_MAX INT_MAX
#define ULONG_MAX UINT_MAX
This is a bit confusing because it seems to me that all integral data types are the same.
I had this issue because I was trying to define a "data_types.h" as following:
typedef char char_t; /* 8-bit signed integer */
typedef unsigned char uchar_t; /* 8-bit unsigned integer */
typedef short int16_t; /* 16-bit signed integer */
typedef unsigned short uint16_t; /* 16-bit unsigned integer */
typedef int int32_t; /* 32-bit signed integer */
typedef unsigned int uint32_t; /* 32-bit unsigned integer */
typedef float float_t; /* 32-bit floating-point */
typedef long double double_t; /* 64-bit floating-point */
Thanks,
Imanol
Hi,
No, we did not find errors.
However, I have one last question. We have a couple of variables mapped to a region of memory with the attribute "WIDTH = 16". What happens with these variables, they are variables of 32 bits but we just access the least significant 16 bits?
for example I could have:
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
uint16_t ui16_var; /* mapped to the 16 width memory */
uint32_t ui32_var; /* mapped to the 32 width memory */
ui32_var = 0xFF0000FF;
ui16_var = ui32_var;
Which is the value of ui16_var? is it 0x00FF?
Regards,
Imanol
Hi,
In the example you give below, the value stored in ui16_var would be 0x00FF. You can test this by making simple changes to the LDF.
Regards,
Craig.
Please log in to reply.