#include <stdio.h>
-#include <stdlib.h>
+#include <stdint.h> /* Because typing unsigned char takes too much characters*/
-void print(char *address, unsigned int size)
+void pm(uint8_t *a, size_t s)
{
- for(unsigned char i = 0; i < size; i++) {
- unsigned char value = (unsigned char)*(address + i);
- printf("%p 0x%02X %3u\n", address + i, value, value);
- }
+ for(uint8_t i = 0; i < s; i++)
+ printf("%p\t0x%02X\t\t%3u\n", a + i, *(a + i), *(a + i));
}
int main(void)
long sn1 = 4109503;
long sn2 = 4202015;
int y[2] = {0x11223344, 0x44332211};
- printf("address content (hex) content(dec)\n");
- printf("------------------------------------------\n");
- print((char *)&i, sizeof(i));
- print((char *)&x, sizeof(x));
- print((char *)&sn1, sizeof(sn1));
- print((char *)&sn2, sizeof(sn2));
- print((char *)&y, 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));
return 0;
}
#include <stdbool.h>
int main(void){
- printf("A bool uses %lu bytes\n", sizeof(bool));
+ printf("A bool uses %zu bytes\n", sizeof(bool));
printf("Hex representation of true: %X\n", true);
printf("Hex representation of false: %X\n", false);
/* Running the following code shows that all but the 0x00 byte evaluate true */