/**
   @file

   This program tests the size and the organisation of an integer on
   the local machine, with the local compiler.

*/

/*
  Copyright (c) Andreas Hofmeier
  (www.an-h.de, www.an-h.de.vu, www.lgut.uni-bremen.de/an-h/)
  
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <stdio.h>


main(int argc, char *argv[]) {
  unsigned int i;
  int size = sizeof(i);
  unsigned char *s, c;

  // make sure, that the size of the integer is greater or equal than
  // two bytes
  printf("testing integer...\n");
  printf("  sizeof(int) = %d Bytes (%d Bits)\n", size, size * 8);
  if (size < 2) {
    fail("The size of integer must be greater or equal that two " \
	 "bytes (or 16 bits)", 1);
  }
  s = (char *) &i;
  printf("  organisation: ");
  for (i = 1; i <= 128; i = i * 2) {
    c = (unsigned char) i;
    if ((s[0] != c) ||
	(s[1] != 0)) {
      fail("organisation of Integer is on this machine different, " \
	   "than the library expect.", 1);
    }
    printf("%d ", i);
  }
  for (i = 256; i <= 32768; i = i * 2) {
    c = (unsigned char) (i / 256);
    if ((s[0] != 0) ||
	(s[1] != c)) {
      fail("organisation of Integer is on this machine different, " \
	   "than the library expect.", 1);
    }
    printf("%d ", i);
  }
  printf(" OK.\n");
  exit(0);
}
