C Standard Library Extensions
1.0.5
|
00001 /* $Id: cxmacros.h,v 1.6 2007/12/12 12:09:41 scastro Exp $ 00002 * 00003 * This file is part of the ESO C Extension Library 00004 * Copyright (C) 2001-2006 European Southern Observatory 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 /* 00022 * $Author: scastro $ 00023 * $Date: 2007/12/12 12:09:41 $ 00024 * $Revision: 1.6 $ 00025 * $Name: cpl-5_3_0-BRANCH $ 00026 */ 00027 00028 00029 /* 00030 * This file MUST not include any other cext header file. 00031 */ 00032 00033 #ifndef CX_MACROS_H 00034 #define CX_MACROS_H 00035 00036 00037 /* 00038 * Get the system's definition of NULL from stddef.h 00039 */ 00040 00041 #include <stddef.h> 00042 00043 00044 /* 00045 * An alias for __extension__ 00046 */ 00047 00048 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8) 00049 # define CX_GNUC_EXTENSION __extension__ 00050 #else 00051 # define CX_GNUC_EXTENSION 00052 #endif 00053 00054 00055 /* 00056 * Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with macros. 00057 */ 00058 00059 #if defined (__GNUC__) && (__GNUC__ < 3) 00060 # define CX_GNUC_FUNCTION __FUNCTION__ 00061 # define CX_GNUC_PRETTY_FUNCTION __PRETTY_FUNCTION__ 00062 #else /* !__GNUC__ */ 00063 # define CX_GNUC_FUNCTION "" 00064 # define CX_GNUC_PRETTY_FUNCTION "" 00065 #endif /* !__GNUC__ */ 00066 00067 #define CX_STRINGIFY(macro) CX_STRINGIFY_ARG(macro) 00068 #define CX_STRINGIFY_ARG(contents) #contents 00069 00070 00071 /* 00072 * String identifier for the current code position 00073 */ 00074 00075 #if defined (__GNUC__) && (__GNUC__ < 3) 00076 # define CX_CODE_POS __FILE__ ":" CX_STRINGIFY(__LINE__) ":" __PRETTY_FUNCTION__ "()" 00077 #else 00078 # define CX_CODE_POS __FILE__ ":" CX_STRINGIFY(__LINE__) 00079 #endif 00080 00081 00082 /* 00083 * C code guard 00084 */ 00085 00086 #undef CX_BEGIN_DECLS 00087 #undef CX_END_DECLS 00088 00089 #ifdef __cplusplus 00090 # define CX_BEGIN_DECLS extern "C" { 00091 # define CX_END_DECLS } 00092 #else 00093 # define CX_BEGIN_DECLS /* empty */ 00094 # define CX_END_DECLS /* empty */ 00095 #endif 00096 00097 00098 /* 00099 * Some popular macros. If the system provides already a definition for some 00100 * of them this definition is used, assuming the definition is correct. 00101 */ 00102 00103 #ifndef NULL 00104 # ifdef __cplusplus 00105 # define NULL (0L) 00106 # else /* !__cplusplus */ 00107 # define NULL ((void *) 0) 00108 # endif /* !__cplusplus */ 00109 #endif 00110 00111 #ifndef FALSE 00112 # define FALSE (0) 00113 #endif 00114 00115 #ifndef TRUE 00116 # define TRUE (!FALSE) 00117 #endif 00118 00119 #ifndef CX_MIN 00120 # define CX_MIN(a, b) ((a) < (b) ? (a) : (b)) 00121 #endif 00122 /*#undef MIN 00123 #define MIN(a, b) ((a) < (b) ? (a) : (b))*/ 00124 00125 #ifndef CX_MAX 00126 # define CX_MAX(a, b) ((a) > (b) ? (a) : (b)) 00127 #endif 00128 /*#undef MAX 00129 #define MAX(a, b) ((a) > (b) ? (a) : (b))*/ 00130 00131 #ifndef CX_ABS 00132 # define CX_ABS(a) ((a) < (0) ? -(a) : (a)) 00133 #endif 00134 /*#undef ABS 00135 #define ABS(a) ((a) < (0) ? -(a) : (a))*/ 00136 00137 #ifndef CX_CLAMP 00138 # define CX_CLAMP(a, low, high) (((a) > (high)) ? (high) : (((a) < (low)) ? (low) : (a))) 00139 #endif 00140 /*#undef CLAMP 00141 #define CLAMP(a, low, high) (((a) > (high)) ? (high) : (((a) < (low)) ? (low) : (a)))*/ 00142 00143 00144 /* 00145 * Number of elements in an array 00146 */ 00147 00148 #define CX_N_ELEMENTS(array) (sizeof (array) / sizeof ((array)[0])) 00149 00150 #endif /* CX_MACROS_H */