1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#!/bin/sh
cat >myctest.c <<END
#include<stdio.h>
#include<stdint.h>
union u{
int32_t l;
char c[4];
};
int main(int argc, char *argv[])
{
union u val;
printf("%ld ",sizeof(int32_t));
printf("%ld ",sizeof(int16_t));
printf("%ld ",sizeof(int));
val.l=1L;
if (val.c[3]==1)
puts("BIG");
else
puts("LITTLE");
}
END
gcc -std=gnu99 myctest.c -o myctest
rm myctest.c
if [ `./myctest |cut -d' ' -f 1` != 4 ]
then echo "Error : sizeof(long)!=4"
fi
if [ `./myctest |cut -d' ' -f 2` != 2 ]
then echo "Error : sizeof(short)!=2"
fi
if [ `./myctest |cut -d' ' -f 3` != 4 ]
then echo "Error :sizeof(int)!=4"
fi
if [ `./myctest |cut -d' ' -f 4` = LITTLE ]
then
echo "#ifndef LITT_ENDIAN" >defendian.h
echo "#define LITT_ENDIAN 1" >>defendian.h
echo "#endif /* LITT_ENDIAN */" >>defendian.h
echo Little Endian machine detected
else
echo "#ifndef LITT_ENDIAN" >defendian.h
echo "#endif /* LITT_ENDIAN */" >>defendian.h
echo Big Endian machine detected
fi
if [ -f myctest.exe ]; then
rm myctest.exe
fi
if [ -f myctest ]; then
rm myctest
fi
|