]> www.ginac.de Git - cln.git/blobdiff - src/base/cl_macros.h
Fix compilation error on MSVC.
[cln.git] / src / base / cl_macros.h
index d4a19593ed15d8269374eca3f0bfb9b0f988ffe4..30b819cd4b1917ba429c962d97997753760c97bc 100644 (file)
@@ -3,6 +3,9 @@
 #ifndef _CL_MACROS_H
 #define _CL_MACROS_H
 
+#include "cln/types.h"
+#include "cln/exception.h"
+
 // Concatenation of macroexpanded tokens.
 // Example:
 //   #undef x
@@ -29,7 +32,7 @@
 // Declare functions that don't return.
 // nonreturning_function(extern,exit,(void)); == extern void exit (void);
   #ifdef __GNUC__
-    #if (__GNUC__ >= 3) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 90))
+    #if (__GNUC__ >= 3) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 9))
       #define nonreturning_function(storclass,funname,arguments)  \
         storclass void funname arguments __attribute__((__noreturn__))
     #else
@@ -71,8 +74,7 @@
 
 // Denotes a point where control flow can never arrive.
 // NOTREACHED
-  #define NOTREACHED  cl_notreached_abort(__FILE__,__LINE__);
-  nonreturning_function(extern,cl_notreached_abort, (const char* filename, int lineno));
+  #define NOTREACHED  throw notreached_exception(__FILE__,__LINE__);
 
 // Check an arithmetic expression.
 // ASSERT(expr)
@@ -91,7 +93,7 @@
       #if defined(__osf__)
         extern "C" char* alloca (int size);
       #else
-        extern "C" void* alloca (int size);
+        extern "C" void* alloca (size_t size);
       #endif
     #endif
   #elif defined(_AIX)
   #elif defined(WATCOM)
     #include <malloc.h> // defines `alloca' as a macro
   #elif !defined(NO_ALLOCA)
-    extern "C" void* alloca (int size);
+    extern "C" void* alloca (size_t size);
   #endif
 
 // NULL pointer.
   #undef NULL
   #define NULL  0
 
-// Bit number n (0<=n<32)
-  #define bit(n)  (1L<<(n))
+// Bit number n (0<=n<32 or 0<=n<64)
+  #ifdef HAVE_FAST_LONGLONG
+    #define bit(n)  (long long)(1ULL<<(n))
+  #else
+    #define bit(n)  (long)(1UL<<(n))
+  #endif
 // Bit number n (0<n<=32) mod 2^32
-  #define bitm(n)  (2L<<((n)-1))
+  #ifdef HAVE_FAST_LONGLONG
+    #define bitm(n)  (long long)(2ULL<<((n)-1))
+  #else
+    #define bitm(n)  (long)(2UL<<((n)-1))
+  #endif
 // Test bit n in x, n constant, x a cl_uint:
   #if !(defined(__sparc__) || defined(__sparc64__))
     #define bit_test(x,n)  ((x) & bit(n))
         )
     #endif
   #endif
-// minus bit number n (0<=n<32)
-  #define minus_bit(n)  (-1L<<(n))
+// minus bit number n (0<=n<32 or 0<=n<64)
+  #ifdef HAVE_FAST_LONGLONG
+    #define minus_bit(n)  (long long)(-1ULL<<(n))
+  #else
+    #define minus_bit(n)  (long)(-1UL<<(n))
+  #endif
 // minus bit number n (0<n<=32) mod 2^32
-  #define minus_bitm(n)  (-2L<<((n)-1))
+  #ifdef HAVE_FAST_LONGLONG
+    #define minus_bitm(n)  (long long)(-2ULL<<((n)-1))
+  #else
+    #define minus_bitm(n)  (long)(-2UL<<((n)-1))
+  #endif
 
 // Return 2^n, n a constant expression.
-// Same as bit(n), but undefined if n<0 or n>=long_bitsize.
-  #define bitc(n)  (1UL << (((n) >= 0 && (n) < long_bitsize) ? (n) : 0))
+// Same as bit(n), but undefined if n<0 or n>={long_}long_bitsize.
+  #if defined(HAVE_FAST_LONGLONG) || defined(intQsize)
+    #define bitc(n)  (1ULL << (((n) >= 0 && (n) < long_long_bitsize) ? (n) : 0))
+  #else
+    #define bitc(n)  (1UL << (((n) >= 0 && (n) < long_bitsize) ? (n) : 0))
+  #endif
 
 // floor(a,b) for a>=0, b>0 returns floor(a/b).
 // b should be a constant expression.
   #define floor(a_from_floor,b_from_floor)  ((a_from_floor) / (b_from_floor))
-// Save the macro in case we need to include <math.h>.
+// Save the macro in case we need to include <cmath>.
   #define cln_floor(a_from_floor,b_from_floor)  ((a_from_floor) / (b_from_floor))
 
 // ceiling(a,b) for a>=0, b>0 returns ceiling(a/b) = floor((a+b-1)/b).
     }
 
 // doconsttimes(count,statement);
-// führt statement count mal aus (count mal der Code!),
+// führt statement count mal aus (count mal der Code!),
 // wobei count eine constant-expression >=0, <=8 ist.
   #define doconsttimes(count_from_doconsttimes,statement_from_doconsttimes)  \
     { if (0 < (count_from_doconsttimes)) { statement_from_doconsttimes; } \
 // DOCONSTTIMES(count,macroname);
 // ruft count mal den Macro macroname auf (count mal der Code!),
 // wobei count eine constant-expression >=0, <=8 ist.
-// Dabei bekommt macroname der Reihe nach die Werte 0,...,count-1 übergeben.
+// Dabei bekommt macroname der Reihe nach die Werte 0,...,count-1 übergeben.
   #define DOCONSTTIMES(count_from_DOCONSTTIMES,macroname_from_DOCONSTTIMES)  \
     { if (0 < (count_from_DOCONSTTIMES)) { macroname_from_DOCONSTTIMES((0 < (count_from_DOCONSTTIMES) ? 0 : 0)); } \
       if (1 < (count_from_DOCONSTTIMES)) { macroname_from_DOCONSTTIMES((1 < (count_from_DOCONSTTIMES) ? 1 : 0)); } \
 
 // Inside a class definition:
 // Overload `new' so that a class object can be allocated anywhere.
-#if !((defined(__rs6000__) || defined(__alpha__)) && !defined(__GNUC__))
 #define ALLOCATE_ANYWHERE(classname)  \
     /* Ability to place an object at a given address. */               \
 public:                                                                        \
-    void* operator new (size_t size) { return cl_malloc_hook(size); }  \
+    void* operator new (size_t size) { return malloc_hook(size); }     \
     void* operator new (size_t size, classname* ptr) { unused size; return ptr; } \
-    void operator delete (void* ptr) { cl_free_hook(ptr); }
-#else
-// For some compilers, work around template problem with "classname".
-#define ALLOCATE_ANYWHERE(classname)  \
-    /* Ability to place an object at a given address. */               \
-public:                                                                        \
-    void* operator new (size_t size) { return cl_malloc_hook(size); }  \
-    void* operator new (size_t size, void* ptr) { unused size; return ptr; } \
-    void operator delete (void* ptr) { cl_free_hook(ptr); }
-#endif
+    void operator delete (void* ptr) { free_hook(ptr); }
 
 // init1(type, object) (value);
 // initializes `object' with `value', by calling `type''s constructor.
@@ -243,9 +255,6 @@ public:                                                                     \
 // it's a shame!)
 #define init1(type,lvalue)  (void) new (&(lvalue)) type
 
-// MAYBE_INLINE normally expands to nothing.
-// Useful for including the implementation of some file inline into another.
-  #define MAYBE_INLINE
-  #define MAYBE_INLINE2
+#include "base/cl_maybe_inline.h"
 
 #endif /* _CL_MACROS_H */