5.14 属性声明:mode
属性声明:mode
显式指定数据类型所占的字节数
使用示例
typedef int s8 __attribute__((mode(QI)));
typedef unsigned int us8 __attribute__((mode(QI)));
mode属性参数
属性参数 | 描述 |
---|---|
QI | An integer that is as wide as the smallest addressable unit, usually 8 bits. |
HI | An integer, twice as wide as a QI mode integer, usually 16 bits. |
SI | An integer, four times as wide as a QI mode integer, usually 32 bits. |
DI | An integer, eight times as wide as a QI mode integer, usually 64 bits. |
SF | A floating point value, as wide as a SI mode integer, usually 32 bits. |
DF | A floating point value, as wide as a DI mode integer, usually 64 bits. |
代码
#include<stdio.h>
typedef int s8 __attribute__((mode(QI)));
typedef int s16 __attribute__((mode(HI)));
typedef int s32 __attribute__((mode(SI)));
typedef int s64 __attribute__((mode(DI)));
typedef unsigned int us8 __attribute__((mode(QI)));
typedef unsigned int us16 __attribute__((mode(HI)));
typedef unsigned int us32 __attribute__((mode(SI)));
typedef unsigned int us64 __attribute__((mode(DI)));
typedef float f32 __attribute__((mode(SF)));
typedef float f64 __attribute__((mode(DF)));
int main(void)
{
s8 i;
printf("i: %d\n",sizeof(i));
printf("%d\n",sizeof(s8));
printf("%d\n",sizeof(s16));
printf("%d\n",sizeof(s32));
printf("%d\n",sizeof(s64));
printf("%d\n",sizeof(us8));
printf("%d\n",sizeof(us16));
printf("%d\n",sizeof(us32));
printf("%d\n",sizeof(us64));
printf("%d\n",sizeof(f32));
printf("%d\n",sizeof(f64));
return 0;
}