On the processor I am programming on, there can be 64-bit, 31-bit and 24-bit pointers.
I'm trying to extract a 24-bit pointer out of a 4-byte word. The first 8 bits in the 4-byte word can be flags that are set. The last 3 bytes will be a pointer, addressable for up to 16mb.
For example, the 4-byte value might be 0x7F000010 which would point to location 0x00000010 in storage.
I've accomplished my goal of extracting it via this code sequence:
It works, however, I get an informational message for line 11 as follows:Code:#include <stdio.h> int main(void) { void * my_32_ptr = (void *) 0x7F000010 ; void * my_24_ptr ; struct { int : 8 ; int int24 : 24 ; } addr24 ; #define int24 addr24.int24 int24 = (int) my_32_ptr ; <--- line 11 my_24_ptr = (void *) int24 ; printf("my_24_ptr = %08X\n", my_24_ptr) ; return 0 ; }
INFORMATIONAL CCN3451 MISC.C(PTR24):11 The target integral type cannot hold all possible values of the source integral type.
At runtime, the first byte gets lopped off as desired.
What's a better method to extract the last 3 bytes of my_32_ptr to avoid the compiler's informational message?
My processor is little endian, so no concerns about the ordering of values in the 4-byte word.
Thanks.