I run a quick test to make sure I have pointer arithmetic:
main.c
#include <stdio.h> #include <stdlib.h> #define ADDRESS 0xC0DCA11501LL #define LENGTH 5 void print_address( char *, char ); /* Main program */ int main( int argc, char *argv[] ) { char nums[ LENGTH ]; /* LSB first */ for( int i = 0; i < LENGTH; i++ ) { nums[ i ] = ( ADDRESS >> ( 8 * i ) ) & 0xFF; } print_address( nums, LENGTH ); system("PAUSE"); return 0; } void print_address( char *data, char len ) { char *data_ptr = data; while( len-- ) { printf( "%X\n", *data_ptr++ ); } }
I expect ADDRESS bytes to be printed in LSB format in hexadecimal format. But the last 3 bytes seem to be printed with 32-bit length:
1 15 FFFFFFA1 FFFFFFDC FFFFFFC0 Press any key to continue . . .
Is this because of my bitrate arithmetic, something compiler specific, some printf() behavior?
(I am using MinGW GCC v6.3.0 for Windows 10 to compile.)
source share