You can either do as @icepack said, or change your struct definition like so:
typedef struct {
int data[256];
} TransferData;
TransferData *readData;
readData = malloc(sizeof(TransferData));
Edit: Note that it's preferable to use sizeof
with variables instead of types to avoid repetition:
readData = malloc(sizeof(*readData));
But be careful not to accidentally pass the size of a pointer when using this style.
Without the typedef
, you need to write struct StructType
in C, which you don't need in C++. As said in the comments, casting the result of malloc
is unnecessary in C, and just clutters your code. It is necessary in C++, but you shouldn't be using malloc
there.