00001 #include <stdio.h>
00002
00003 #ifndef ALIGN
00004 #error Missing ALIGN
00005 #endif
00006
00007 #ifndef TYPE
00008 #error Missing TYPE
00009 #endif
00010
00011 #define SZ sizeof(TYPE)/ALIGN
00012
00013 #ifdef __hpux
00014 typedef __float80 longdouble;
00015 #else
00016 typedef long double longdouble;
00017 #endif
00018
00019 #pragma pack 1
00020 struct foo {
00021 TYPE f;
00022 char x[ALIGN];
00023 } __attribute__((packed));
00024
00025 const TYPE val = 1.5;
00026
00027 static void
00028 fail(const char *op, int t, void *p)
00029 {
00030 fprintf(stderr, "FAIL: %s: %d, %p\n", op, t, p);
00031 fflush(stderr);
00032 }
00033
00034 static void
00035 swap(char *p)
00036 {
00037
00038
00039
00040
00041
00042
00043
00044 }
00045
00046 static TYPE
00047 collect(const char *src)
00048 {
00049 TYPE f;
00050
00051 memcpy(&f, src, sizeof(TYPE));
00052 return (f);
00053 }
00054
00055 static void
00056 supply(char *src)
00057 {
00058 memcpy(src, &val, sizeof(TYPE));
00059 }
00060
00061 static TYPE
00062 load(struct foo *f)
00063 {
00064 swap(&f->f);
00065 return f->f;
00066 }
00067
00068 static void
00069 store(struct foo *f, TYPE v)
00070 {
00071 f->f = v;
00072 swap(&f->f);
00073 }
00074
00075 int
00076 main()
00077 {
00078 static struct foo src[SZ];
00079 TYPE f;
00080 int i;
00081
00082 for (i = 0; i < SZ; i++) {
00083
00084 store(src + i, val);
00085 f = collect((const char *)&src[i].f);
00086 if (f != val) {
00087 fail("store", i, src + i);
00088 supply((char *)&src[i].f);
00089 }
00090
00091 f = load(src + i);
00092 if (f != val)
00093 fail("load", i, src + i);
00094 }
00095 return (0);
00096 }