CC=gcc
CFLAGS=-std=c99 -Wall -Wextra
-all: exercise1
+all: exercise1 exercise2
+
+exercise2: exercise2.c
+ $(CC) $(CFLAGS) -O3 exercise2.c -o exercise2
exercise1: exercise1b.c exercise1d.c
$(CC) $(CFLAGS) exercise1b.c -o exercise1b
$(CC) $(CFLAGS) exercise1d.c -o exercise1d
clean:
- $(RM) exercise1b exercise1d
+ $(RM) exercise1b exercise1d exercise2
+#include <stdio.h>
+#include <stdlib.h>
+
+void print(char *address, unsigned int size)
+{
+ printf("address: %p, size: %u, psize: %u\n", address, size, sizeof(address));
+ for(unsigned char i=0; i<size; i++)
+ {
+ int value = *((char*)(address+i));
+ printf("%p %x %u\n", address+i, value, value);
+ }
+}
+
int main(void)
{
+ short i = 0x1234;
+ char x = -127;
+ long sn1 = 4109503;/*
+ long sn2 = 4202015;
+ int y[2] = {0x11223344, 0x443332211};*/
+ printf("address content (hex) content(dec)\n");
+ print((char *)&i, sizeof(i));
+ print((char *)&x, sizeof(x));
+ print((char *)&sn1, sizeof(sn1));
+ return 0;
}