I'm trying to declare a static C struct. The declaration of the struct is as follows:
typedef struct { int a; int b; int c }dummy_struct; However when making the definition of the struct, I want to store a value in c that is calculated using the values in a and b and another constant value.
My initial idea was to store it this way:
static dummy_struct dummy = { .a = 5, .b = 10, .c = CALC_VALUE(0.5, a, b) } And then I would define CALC_VALUE as a preprocessor so that I could run some calulations on a, b and the constant value like so:
#define CALC_VALUE(constant, a, b) (constant * (a/2) * (b*3)) But my compiler complains every time I do this so I'm resorting to the following method for the declaration:
static dummy_struct dummy = { .a = 5, .b = 10, .c = CALC_VALUE(0.5, 5, 10) } Is there a cleaner way to do this without using #defines for 'a' and 'b'
0.5in the struct, and then do the calculation where you need the value?