template_types.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00039 #include <stdio.h>
00040
00041 #define SHOWSIZE(def, type) \
00042 printf("#define %s %d\n", sizeof(type));
00043
00044 int main(int argc, char *argv[]) {
00045 const char *int8 = 0;
00046 const char *int16 = 0;
00047 const char *int32 = 0;
00048 const char *int64 = 0;
00049 const char *L8 = 0;
00050 const char *L16 = 0;
00051 const char *L32 = 0;
00052 const char *L64 = 0;
00053
00054 printf("#ifndef FASTLIB_BASE_TYPE_H\n");
00055 printf("#define FASTLIB_BASE_TYPE_H\n");
00056 printf("\n");
00057
00058 if (sizeof(char) == 1) {
00059 int8 = "char";
00060 L8 = "";
00061 } else {
00062 fprintf(stderr, "No 8-bit integral type.\n");
00063 }
00064 if (int8) {
00065 printf("typedef unsigned %s uint8;\n", int8);
00066 printf("typedef signed %s int8;\n", int8);
00067 printf("#define L8 \"%s\"\n", L8);
00068 printf("\n");
00069 }
00070
00071 if (sizeof(short) == 2) {
00072 int16 = "short";
00073 L16 = "";
00074 } else {
00075 fprintf(stderr, "No 16-bit integral type.\n");
00076 }
00077 if (int16) {
00078 printf("typedef unsigned %s uint16;\n", int16);
00079 printf("typedef signed %s int16;\n", int16);
00080 printf("#define L16 \"%s\"\n", L16);
00081 printf("\n");
00082 }
00083
00084 if (sizeof(int) == 4) {
00085 int32 = "int";
00086 L32 = "";
00087 } else if (sizeof(long) == 4) {
00088 int32 = "long";
00089 L32 = "l";
00090 } else {
00091 fprintf(stderr, "No 32-bit integral type.\n");
00092 }
00093 if (int32) {
00094 printf("typedef unsigned %s uint32;\n", int32);
00095 printf("typedef signed %s int32;\n", int32);
00096 printf("#define L32 \"%s\"\n", L32);
00097 printf("\n");
00098 }
00099
00100 if (sizeof(long) == 8) {
00101 int64 = "long";
00102 L64 = "l";
00103 } else if (sizeof(long long) == 8) {
00104 int64 = "long long";
00105 L64 = "ll";
00106 } else {
00107 fprintf(stderr, "No 64-bit integral type.\n");
00108 }
00109 if (int64) {
00110 printf("typedef unsigned %s uint64;\n", int64);
00111 printf("typedef signed %s int64;\n", int64);
00112 printf("#define L64 \"%s\"\n", L64);
00113 printf("\n");
00114 }
00115
00116 if (sizeof(float) == 4) {
00117 printf("typedef float float32;\n");
00118 } else {
00119 fprintf(stderr, "No 32-bit floating-point type.\n");
00120 }
00121 if (sizeof(double) == 8) {
00122 printf("typedef double float64;\n");
00123 } else {
00124 fprintf(stderr, "No 64-bit floating-point type.\n");
00125 }
00126 printf("\n");
00127
00128 printf("#endif\n");
00129
00130 return 0;
00131 }