template_types.c

Go to the documentation of this file.
00001 /* MLPACK 0.2
00002  *
00003  * Copyright (c) 2008, 2009 Alexander Gray,
00004  *                          Garry Boyer,
00005  *                          Ryan Riegel,
00006  *                          Nikolaos Vasiloglou,
00007  *                          Dongryeol Lee,
00008  *                          Chip Mappus, 
00009  *                          Nishant Mehta,
00010  *                          Hua Ouyang,
00011  *                          Parikshit Ram,
00012  *                          Long Tran,
00013  *                          Wee Chin Wong
00014  *
00015  * Copyright (c) 2008, 2009 Georgia Institute of Technology
00016  *
00017  * This program is free software; you can redistribute it and/or
00018  * modify it under the terms of the GNU General Public License as
00019  * published by the Free Software Foundation; either version 2 of the
00020  * License, or (at your option) any later version.
00021  *
00022  * This program is distributed in the hope that it will be useful, but
00023  * WITHOUT ANY WARRANTY; without even the implied warranty of
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025  * General Public License for more details.
00026  *
00027  * You should have received a copy of the GNU General Public License
00028  * along with this program; if not, write to the Free Software
00029  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00030  * 02110-1301, USA.
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 }
Generated on Mon Jan 24 12:04:37 2011 for FASTlib by  doxygen 1.6.3