The easiest and most straight forward way is to use a union
#define array_size_int32 11
#define array_size_int8 44
typedef union{
int32_t const_data[array_size_int32];
int8_t buffer[array_size_int8];
}my_union_t;
Example usage:
/* initialize union members */
my_union_t my_union = {
.const_data = {
0x12345678,
0x12345678,
0x12345678,
0x12345678,
0x12345678,
0x12345678,
0x12345678,
0x12345678,
0x12345678,
0x12345678,
0x12345678,
},
};
Example way to print:
uint8_t i;
for(i = 0; i < array_size_int8; i++){
/* mask off sign extension bits */
printf("my_union.buffer[%d] = %x\n", i, my_union.buffer[i] & 0xff);
}
You can try the code out here
EDIT:
I should add that this works because the memory size needed to allocate either array is the same and you'll run in to problems if you change the #define
's without taking that in to consideration.
For example,
#define array_size_int32 10 //40 bytes
#define array_size_int8 45 //45 bytes