尝试初始化此typedef结构时,我做错了什么。
我在linux中做了同样的声明,我可以创造完美。
这是定义:
typedef struct {
char mask; /* char data will be bitwise AND with this */
char lead; /* start bytes of current char in utf-8 encoded character */
uint32_t beg; /* beginning of codepoint range */
uint32_t end; /* end of codepoint range */
int bits_stored; /* the number of bits from the codepoint that fits in char */
}utf_t;
utf_t * utf[];
/* mask lead beg end bits */
utf_t * utf[] = {
[0] = &(utf_t){0b00111111, 0b10000000, 0, 0, 6 },
[1] = &(utf_t){0b01111111, 0b00000000, 0000, 0177, 7 },
[2] = &(utf_t){0b00011111, 0b11000000, 0200, 03777, 5 },
[3] = &(utf_t){0b00001111, 0b11100000, 04000, 0177777, 4 },
[4] = &(utf_t){0b00000111, 0b11110000, 0200000, 04177777, 3 },
&(utf_t){0},
};
当我尝试编译时,我不创建假脱机文件,但是在作业日志中显示以下消息:
Message ID . . . . . . : MCH3601 Severity . . . . . . . : 40
Message type . . . . . : Escape
Date sent . . . . . . : 18/11/19 Time sent . . . . . . : 10:02:49
Message . . . . : Pointer not set for location referenced.
Cause . . . . . : A pointer was used, either directly or as a basing
pointer, that has not been set to an address.
有人可以告诉我我做错了什么吗? 谢谢。
关于
答案 0 :(得分:1)
根据文档here,IBM i C / C ++编译器不识别二进制整数文字。实际上,如果我尝试编译您的代码段,则二进制文字上的代码段将失败。但是,如果我将二进制文字转换为十六进制文字,它将起作用:
#include <stdint.h>
typedef struct {
char mask; /* char data will be bitwise AND with this */
char lead; /* start bytes of current char in utf-8 encoded character */
uint32_t beg; /* beginning of codepoint range */
uint32_t end; /* end of codepoint range */
int bits_stored; /* the number of bits from the codepoint that fits in char */
}utf_t;
utf_t * utf[];
/* mask lead beg end bits */
utf_t * utf[] = {
[0] = &(utf_t){0x3f, 0x80, 0, 0, 6 },
[1] = &(utf_t){0x7f, 0x00, 0000, 0177, 7 },
[2] = &(utf_t){0x1f, 0xc0, 0200, 03777, 5 },
[3] = &(utf_t){0x0f, 0xe0, 04000, 0177777, 4 },
[4] = &(utf_t){0x07, 0xf0, 0200000, 04177777, 3 },
&(utf_t){0},
};
答案 1 :(得分:0)
您在此处使用复合文字:
两种初始化方式:
utf_t *utf[6];
utf_t *utf1[] = {
&(utf_t){0b00111111, 0b10000000, 0, 0, 6 },
&(utf_t){0b01111111, 0b00000000, 0000, 0177, 7 },
&(utf_t){0b00011111, 0b11000000, 0200, 03777, 5 },
&(utf_t){0b00001111, 0b11100000, 04000, 0177777, 4 },
&(utf_t){0b00000111, 0b11110000, 0200000, 04177777, 3 },
&(utf_t){0},
};
void foo(void)
{
memcpy(utf, (utf_t *[]){
&(utf_t){0b00111111, 0b10000000, 0, 0, 6 },
&(utf_t){0b01111111, 0b00000000, 0000, 0177, 7 },
&(utf_t){0b00011111, 0b11000000, 0200, 03777, 5 },
&(utf_t){0b00001111, 0b11100000, 04000, 0177777, 4 },
&(utf_t){0b00000111, 0b11110000, 0200000, 04177777, 3 },
&(utf_t){0},
}, sizeof(utf));
}
int main()
{
int arr[1000];
foo();
memset(arr,0, sizeof(arr));
printf("%hhu %hhu %u\n", utf[2] -> mask, utf[2] -> lead, utf[2] -> beg);
printf("%hhu %hhu %u", utf1[2] -> mask, utf1[2] -> lead, utf1[2] -> beg);
}