result of sizeof expected expression on array declaration
in drone.h
I have a struct
typedef struct {
char name[MAX_DRONE_NAME_LENGTH];
enum drone_model model;
uint8_t status_bitarr;
} drone;
and a define
#define DRONE_STATUS_LENGTH (8*sizeof( ((drone*)0)->status_bitarr ))
I can use the value of this define, as well as the original expression in main.c
printf("%d\n", (8*sizeof( ((drone*)0)->status_bitarr )) );
printf("%d\n", DRONE_STATUS_LENGTH);
static char bob[DRONE_STATUS_LENGTH]="aaaaaaaa";
printf("%c\n", bob[2]);
8
8
a
but in drone.c the line
static char result[DRONE_STATUS_LENGTH];
produces an "expected expression error"
./drone.c:34:22: error: expected expression
static char result[DRONE_STATUS_LENGTH]={0};
^
./drone.h:24:48: note: expanded from macro 'DRONE_STATUS_LENGTH'
#define DRONE_STATUS_LENGTH (8*sizeof( ((drone*)0)->status_bitarr ))
replacing with a hardcoded value fixes error, but I want to use sizeof
how do I get it to work?
C, sizeof, array, c macro, c defines