如何初始化unsigned char数组?

时间:2012-02-19 18:44:55

标签: c multidimensional-array

我真正想要实现的是一组动态字节模式,当我缓冲二进制文件时,我可以将其用作模式搜索器。但我现在开始基本。我有以下代码,我基于StackOverflow上的示例。

How to Initialize a Multidimensional Char Array in C?

typedef unsigned char BYTE;

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

    return 0;
}

我使用mingw32 for Windows编译它。

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

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

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]

我不明白这个警告的性质。我该如何解决它?感谢。

1 个答案:

答案 0 :(得分:6)

*

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

您想要一个charBYTE p[2][4]的多维数组,而不是pointer-to-char的多维数组。