gpt4 book ai didi

c - 在 C 中初始化 typedef 结构时出现问题 (Iseries/AS400)

转载 作者:行者123 更新时间:2023-11-30 19:00:52 24 4
gpt4 key购买 nike

当我尝试初始化这个 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.

有人可以告诉我我做错了什么吗?谢谢。

问候,

最佳答案

根据文档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},
};

关于c - 在 C 中初始化 typedef 结构时出现问题 (Iseries/AS400),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58911104/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com