// Beispielprogramm
#include <stdio.h>
void hexdump (void *startaddr, void *endaddr);

// globale Variablen
char c = 'C';  char d = 'D';  char e = 'E';
char wort[5] = "wort";  // = [ 'w','o','r','t',0 ]
int  i = 0x12345678;  int  j = 0xAABBCCDD;

typedef struct {
  int r, s, t;
  char u[20];
  float v, w;
} struktur;
struktur s1 = { 0x11111111, 0x22222222, 0x33333333, "Hallo", 3.14, 4.15 };
struktur s2 = { 0x44444444, 0x55555555, 0x66666666, "Welt",  5.16, 6.17 };
struktur s3 = { 0x77777777, 0x88888888, 0x99999999, "Ende",  7.18, 8.19 };

int main () {
  printf ("Adresse von c    = %p  0x%04x\n", &c,  (int)&c-(int)&c);
  printf ("Adresse von d    = %p  0x%04x\n", &d,  (int)&d-(int)&c);
  printf ("Adresse von e    = %p  0x%04x\n", &e,  (int)&e-(int)&c);
  printf ("Adresse von wort = %p  0x%04x\n", wort,(int)wort-(int)&c);
  printf ("Adresse von i    = %p  0x%04x\n", &i,  (int)&i-(int)&c);
  printf ("Adresse von j    = %p  0x%04x\n", &j,  (int)&j-(int)&c);
  printf ("           |s1|  = 0x%x\n", sizeof(s1));
  printf ("Adresse von s1   = %p  0x%04x\n", &s1, (int)&s1-(int)&c);
  printf ("Adresse von s2   = %p  0x%04x\n", &s2, (int)&s2-(int)&c);
  printf ("Adresse von s3   = %p  0x%04x\n", &s3, (int)&s3-(int)&c);
  hexdump (&c, &c+224);  // aus externer Bibliothek
}

typedef unsigned char byte;
#define PEEK(addr)    (*(byte *)(addr))
void hexdump (void *startaddr, void *endaddr) {
  long i;
  for (i=(long)startaddr; i < (long)endaddr; i+=16) {
    printf ("%08x  ", i);                   // address
    long j;
    for (j = i;  j < i+16;  j++) {      // hex values
      printf ("%02x ", (byte)PEEK(j));
      if (j==i+7) printf (" ");
    };
    printf (" ");
    for (j = i;  j < i+16;  j++) {      // characters
      char z = PEEK(j);
      if ((z>=32) && (z<127)) {
        printf ("%c", PEEK(j));
      } else {
        printf (".");
      };
    };
    printf ("\n");
  };
};

