如何初始化无符号字符数组?

时间:2022-01-06 21:29:46

What I am really trying to achieve is an array of dynamic byte patterns that I can use as a pattern searcher when I buffer binary files. But I am starting off basic for now. I have the following code that I based off of an example found on *.

我真正想要实现的是一个动态字节模式的数组,当我缓冲二进制文件时,我可以使用它作为模式搜索器。但我现在先从basic开始。我基于*上的一个示例,有以下代码。

How to Initialize a Multidimensional Char Array in C?

如何在C中初始化多维字符数组?

typedef unsigned char BYTE;

int main()
{
    BYTE *p[2][4] = {
        {0x44,0x58,0x54,0x31},
        {0x44,0x58,0x54,0x00}
    };

    return 0;
}

I compile it with mingw32 for Windows.

我使用mingw32对Windows进行编译。

D:\> gcc example.c -o example.exe

I get the following warnings when I try to compile.

当我尝试编译时,会得到以下警告。

example.c: In function 'main':
example.c:6:3: warning: initialization makes pointer from integer without a cast [enabled by default]
example.c:6:3: warning: (near initialization for 'p[0][0]') [enabled by default]
example.c:6:3: warning: initialization makes pointer from integer without a cast [enabled by default]
example.c:6:3: warning: (near initialization for 'p[0][1]') [enabled by default]
example.c:6:3: warning: initialization makes pointer from integer without a cast [enabled by default]
example.c:6:3: warning: (near initialization for 'p[0][2]') [enabled by default]
example.c:6:3: warning: initialization makes pointer from integer without a cast [enabled by default]
example.c:6:3: warning: (near initialization for 'p[0][3]') [enabled by default]
example.c:7:3: warning: initialization makes pointer from integer without a cast [enabled by default]
example.c:7:3: warning: (near initialization for 'p[1][0]') [enabled by default]
example.c:7:3: warning: initialization makes pointer from integer without a cast [enabled by default]
example.c:7:3: warning: (near initialization for 'p[1][1]') [enabled by default]
example.c:7:3: warning: initialization makes pointer from integer without a cast [enabled by default]
example.c:7:3: warning: (near initialization for 'p[1][2]') [enabled by default]

I don't understand the nature of this warning. How do I go about resolving it? Thanks.

我不理解这个警告的性质。我该如何解决这个问题呢?谢谢。

1 个解决方案

#1


5  

Drop the * from BYTE *p[2][4]:

将*从字节*p[2][4]中删除:

BYTE p[2][4] = {
    {0x44,0x58,0x54,0x31},
    {0x44,0x58,0x54,0x00}
};

You want a multidimensional array of char: BYTE p[2][4] not a multidimensional array of pointer-to-char.

您需要一个char: BYTE p[2][4]的多维数组,而不是一个point -to-char的多维数组。

#1


5  

Drop the * from BYTE *p[2][4]:

将*从字节*p[2][4]中删除:

BYTE p[2][4] = {
    {0x44,0x58,0x54,0x31},
    {0x44,0x58,0x54,0x00}
};

You want a multidimensional array of char: BYTE p[2][4] not a multidimensional array of pointer-to-char.

您需要一个char: BYTE p[2][4]的多维数组,而不是一个point -to-char的多维数组。