I have a structure that fits the following layout:
typdef union { BITFIELD_DATA_TYPE bits; //breaks out to 32 bits uint32_t word; } UNION_DATA_TYPE; typedef struct { UNION_DATA_TYPE A; UNION_DATA_TYPE B; UNION_DATA_TYPE C; UNION_DATA_TYPE D; } DATA_BLOCK_TYPE;
At the global scope in a code file, the variable is then declared:
DATA_BLOCK_TYPE GlobalBlock;
I would like to set the initial values of "GlobalBlock" without having to call a function to set this up, since I always expect a specific set of initial values.
I tried at first something like:
DATA_BLOCK_TYPE GlobalBlock = {0x1000, 0x10000, 0x100000, 0x1000000};
However, this resulted in a warning "#70-D integer conversion resulted in truncation".
I converted the values to 0x...L (e.g.: 0x1000L) and then 0x...UL (e.g.: 0x1000UL), but this did not resolve anything. The code would compile; however, the variable was not initialized.
I wrapped the initializer in extra brackets, due to sub members:
DATA_BLOCK_TYPE GlobalBlock = {{0x1000}, {0x10000}, {0x100000}, {0x1000000}};
However, this did not make a difference either.
Doing some searching around, I saw a number of suggestions for initializing by including the member name:
DATA_BLOCK_TYPE GlobalBlock = {{.A = 0}, ...};
When trying this, the warning was converted to an error "#29 expected an expression".
Is there any easy way that I am overlooking to get this initial value set at compile/link time?