#include <stdio.h>
-#include <stdint.h> /* Because typing unsigned char takes too much characters*/
-void pm(uint8_t *a, size_t s)
+void pm(unsigned char *a, size_t s)
{
- for(size_t i = 0; i < s; i++)
- printf("%p\t0x%02X\t\t%3u\n", a + i, *(a + i), *(a + i));
+ for(unsigned char *i = a; i < a+s; i++)
+ printf("%p\t0x%02X\t\t%3u\n", i, *i, *i);
}
int main(void)
long sn1 = 4109503;
long sn2 = 4202015;
int y[2] = {0x11223344, 0x44332211};
+ printf("short i = %zu byte(s)\n", sizeof(i));
+ printf("char x = %zu byte(s)\n", sizeof(x));
+ printf("long sn1 = %zu byte(s)\n", sizeof(sn1));
+ printf("long sn2 = %zu byte(s)\n", sizeof(sn2));
+ printf("int[2] y = %zu byte(s)\n\n", sizeof(y));
printf("address\t\tcontent (hex)\tcontent(dec)\n");
- printf("-------------------------------------------\n");
- pm((uint8_t *)&i, sizeof(i));
- pm((uint8_t *)&x, sizeof(x));
- pm((uint8_t *)&sn1, sizeof(sn1));
- pm((uint8_t *)&sn2, sizeof(sn2));
- pm((uint8_t *)&y, sizeof(y));
+ printf("--------------------------------------------\n");
+ pm((unsigned char *)&i, sizeof(i));
+ pm((unsigned char *)&x, 1);
+ pm((unsigned char *)&sn1, sizeof(sn1));
+ pm((unsigned char *)&sn2, sizeof(sn2));
+ pm((unsigned char *)&y, sizeof(y));
return 0;
}