Sophie

Sophie

distrib > Mandriva > 2007.0 > i586 > media > contrib-release > by-pkgid > 4c9f17ec5da473f7fb52041bb9197c5a > files > 121

kaffe-devel-1.1.8-0.20060723.1mdv2007.0.i586.rpm

/*
 * Try to guess the required alignment for various types
 *
 * Can be used for ALIGNMENT_OF_SIZE() macro for new ports.
 * Note that the macro defaults to the identical mapping.
 *
 * Written by Godmar Back <gback@cs.utah.edu>
 */
#include <stdio.h>

#define A(type, name) \
struct {        \
  unsigned char _;      \
  type   x;     \
} name

A(int, Int);
A(short, Short);
A(long, Long);
A(long long, LongLong);
A(float, Float);
A(double, Double);
A(char, Char);
A(struct { short _; }, ShortStruct);
A(struct { char _; }, CharStruct);
A(struct { int _; }, IntStruct);
A(struct { long _; }, LongStruct);
A(struct { float _; }, FloatStruct);
A(struct { double _; }, DoubleStruct);
A(struct { long long _; }, LongLongStruct);

main()
{
#define P(name) \
  printf("alignment of %15s with size %d -> %d\n", \
        #name, sizeof(name.x), (char*)&name.x - (char*)&name)
  P(Char);
  P(Short);
  P(Int);
  P(Float);
  P(Long);
  P(LongLong);
  P(Double);
  P(CharStruct);
  P(ShortStruct);
  P(IntStruct);
  P(FloatStruct);
  P(LongStruct);
  P(LongLongStruct);
  P(DoubleStruct);
}