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
size_of_const()and what is the +12 offset for? Also0001 0004 0003is not an unambiguous description of the content - 4 digit octal values suggests 12 bit value notuint8_t- or are these character strings representing integers and not 8 bit integers at all? Too much ambiguity to post an answer.bufferasint32_t*? In this case just cast:int32_t* const_data = (int32_t*) buffer