在C中创建BYTE数组结构

时间:2018-05-16 06:55:00

标签: c arrays struct byte

我想在大小为512的C中的结构中创建一个字节数组,但结构的大小最终是该大小的八倍。您能否帮助我了解如何制作所需的数据结构。

这是我目前的代码

#include <stdint.h>

typedef uint8_t BYTE;

typedef struct _ByteArray {

    BYTE *arr[512];
} __attribute__((__packed__))
JPEG;

1 个答案:

答案 0 :(得分:1)

BYTE * arr[512];
 ^   ^  ^   ^
 |   |  |   |
 |   |  |  is an array of 512
 |   |  arr
 |  pointers to
BYTE

您必须将其更改为:

BYTE arr[512];
 ^    ^   ^
 |    |   |
 |    |  is an array of 512 
 |   arr 
BYTE

由于您需要一个字节数组,因此不需要生成struct数据包,因为不会添加填充字节。