I got a code from an old project implementing AES on 802.15.4
It defines the the default key like this:
static uint8_t default_key_source[8] = {0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
and afterwards define a table which uses this in the following manner:
uint8_t mac_key_table[34] =
{
// KeyIdLookupList[1].LookupData : macDefaultKeySource || g_Sec_KeyIndex_1
default_key_source[0], // LookupData[0]
default_key_source[1], // LookupData[1]
default_key_source[2], // LookupData[2]
default_key_source[3], // LookupData[3]
default_key_source[4], // LookupData[4]
default_key_source[5], // LookupData[5]
default_key_source[6], // LookupData[6]
...
}
I get “expression must have a constant value” error on compilation. which is strange because it used to compile on different compiler (don’t know exactly which, but I’m using IAR embedded workbench for ARM)
I tried adding const before the static declaration of the default_key_source. but it didn’t help, I get that the compiler can’t initialize a structure with variables, however these variables are constants, so what’s the problem here ?
An easy way to deal with such a situation in C is to use a macro, to be sure that you’d have to define the constants only in one place: