summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschnetter <schnetter@17b73243-c579-4c4c-a9d2-2d5706c11dac>2004-01-19 21:39:52 +0000
committerschnetter <schnetter@17b73243-c579-4c4c-a9d2-2d5706c11dac>2004-01-19 21:39:52 +0000
commite44d81f5cbbf756904b98e07688e76bdadbd1437 (patch)
treec1d5a077a664537810319be312744968f00c51a1
parent974ed2bedc78ab300f90ecbabdd0ac9c1fcf0589 (diff)
Use inline functions instead of #defines for CCTK_GFINDEX?D if available
git-svn-id: http://svn.cactuscode.org/flesh/trunk@3536 17b73243-c579-4c4c-a9d2-2d5706c11dac
-rw-r--r--src/include/cctk.h59
-rw-r--r--src/include/cctk_DebugDefines.h18
-rw-r--r--src/main/DebugDefines.c19
3 files changed, 54 insertions, 42 deletions
diff --git a/src/include/cctk.h b/src/include/cctk.h
index 59ceaabd..932f305f 100644
--- a/src/include/cctk.h
+++ b/src/include/cctk.h
@@ -123,9 +123,11 @@
#include "cctk_Comm.h"
#include "cctk_CommandLine.h"
#include "cctk_Complex.h"
+#include "cctk_DebugDefines.h"
#include "cctk_Faces.h"
#include "cctk_File.h"
#include "cctk_Flesh.h"
+#include "cctk_FortranString.h"
#include "cctk_Functions.h"
#include "cctk_GHExtensions.h"
#include "cctk_Groups.h"
@@ -148,64 +150,63 @@
* routines/macros to compute the linear index
* of a grid funtion element from its i/j/k dimensions
*
- * For C++ these are defined as inline functions, for C as macros.
- * For CCTK_DEBUG these are external C routines defined in Debug.c.
+ * These are defined as inline functions when the language supports this,
+ * otherwise they are defined as macros.
+ * For CCTK_DEBUG these are external C routines defined in DebugDefines.c.
*/
-#ifdef CCTK_DEBUG
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif /* __cplusplus */
-
-int CCTK_GFINDEX1D (const cGH *GH, int i);
-int CCTK_GFINDEX2D (const cGH *GH, int i, int j);
-int CCTK_GFINDEX3D (const cGH *GH, int i, int j, int k);
-int CCTK_GFINDEX4D (const cGH *GH, int i, int j, int k, int l);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
+#if defined(__cplusplus) || !defined(inline)
+/* The "inline" keyword is supported */
-#else /* CCTK_DEBUG */
-
-#ifdef __cplusplus
-
-inline int CCTK_GFINDEX1D (const cGH *GH, int i)
+static inline int CCTK_GFINDEX1D (const cGH *GH, int i);
+static inline int CCTK_GFINDEX1D (const cGH *GH, int i)
{
GH = GH;
return (i);
}
-inline int CCTK_GFINDEX2D (const cGH *GH, int i, int j)
+static inline int CCTK_GFINDEX2D (const cGH *GH, int i, int j);
+static inline int CCTK_GFINDEX2D (const cGH *GH, int i, int j)
{
return (i + GH->cctk_lsh[0]*j);
}
-inline int CCTK_GFINDEX3D (const cGH *GH, int i, int j, int k)
+static inline int CCTK_GFINDEX3D (const cGH *GH, int i, int j, int k);
+static inline int CCTK_GFINDEX3D (const cGH *GH, int i, int j, int k)
{
return (i + GH->cctk_lsh[0]*(j + GH->cctk_lsh[1]*k));
}
-inline int CCTK_GFINDEX4D (const cGH *GH, int i, int j, int k, int l)
+static inline int CCTK_GFINDEX4D (const cGH *GH, int i, int j, int k, int l);
+static inline int CCTK_GFINDEX4D (const cGH *GH, int i, int j, int k, int l)
{
return (i + GH->cctk_lsh[0]*(j + GH->cctk_lsh[1]*(k + GH->cctk_lsh[2] * l)));
}
-#else /* __cplusplus */
+#else /* ! defined(__cplusplus) && defined(inline) */
+
+#ifdef CCTK_DEBUG
+/* The "inline" keyword is not supported, and we want to debug */
+
+#define CCTK_GFINDEX1D CCTK_GFIndex1D
+#define CCTK_GFINDEX2D CCTK_GFIndex2D
+#define CCTK_GFINDEX3D CCTK_GFIndex3D
+#define CCTK_GFINDEX4D CCTK_GFIndex4D
+
+#else /* ! defined(CCTK_DEBUG) */
+/* The "inline" keyword is not supported, and we want to optimise */
#define CCTK_GFINDEX1D(GH, i) (i)
-#define CCTK_GFINDEX2D(GH, i, j) ((i) + (GH)->cctk_lsh[0] * ((j)))
+#define CCTK_GFINDEX2D(GH, i, j) ((i) + (GH)->cctk_lsh[0] * (j))
#define CCTK_GFINDEX3D(GH, i, j, k) ((i) + (GH)->cctk_lsh[0] * \
((j) + (GH)->cctk_lsh[1] * (k)))
#define CCTK_GFINDEX4D(GH, i, j, k, l) ((i) + (GH)->cctk_lsh[0] * \
((j) + (GH)->cctk_lsh[1] * \
((k) + (GH)->cctk_lsh[2] * (l))))
-#endif /* __cplusplus */
+#endif /* ! defined(CCTK_DEBUG) */
-#endif /* CCTK_DEBUG */
+#endif /* ! defined(__cplusplus) && defined(inline) */
#define CCTK_PRINTSEPARATOR \
diff --git a/src/include/cctk_DebugDefines.h b/src/include/cctk_DebugDefines.h
new file mode 100644
index 00000000..b4b8c445
--- /dev/null
+++ b/src/include/cctk_DebugDefines.h
@@ -0,0 +1,18 @@
+/*@@
+ @file cctk_DebugDefines.h
+ @date Sun 28 Dec 2003
+ @author Erik Schnetter
+ @desc
+ Routines to provide some debugging support for the Cactus code.
+ @enddesc
+ @version $Id$
+ @@*/
+
+/********************************************************************
+ ********************* External Routines **********************
+ ********************************************************************/
+
+int CCTK_GFIndex1D (const cGH *GH, int i);
+int CCTK_GFIndex2D (const cGH *GH, int i, int j);
+int CCTK_GFIndex3D (const cGH *GH, int i, int j, int k);
+int CCTK_GFIndex4D (const cGH *GH, int i, int j, int k, int l);
diff --git a/src/main/DebugDefines.c b/src/main/DebugDefines.c
index c3cbb081..43383489 100644
--- a/src/main/DebugDefines.c
+++ b/src/main/DebugDefines.c
@@ -10,6 +10,7 @@
#include "cctk_Config.h"
#include "cctk_Flesh.h"
+#include "cctk_DebugDefines.h"
static const char *rcsid = "$Header$";
@@ -19,15 +20,9 @@ CCTK_FILEVERSION(main_DebugDefines_c);
/********************************************************************
********************* External Routines **********************
********************************************************************/
-#ifdef CCTK_DEBUG
-int CCTK_GFINDEX1D (const cGH *GH, int i);
-int CCTK_GFINDEX2D (const cGH *GH, int i, int j);
-int CCTK_GFINDEX3D (const cGH *GH, int i, int j, int k);
-int CCTK_GFINDEX4D (const cGH *GH, int i, int j, int k, int l);
-
/*@@
- @routine CCTK_GFINDEX?D
+ @routine CCTK_GFIndex?D
@date Tue 2 Jul 2001
@author Thomas Radke
@desc
@@ -51,25 +46,23 @@ int CCTK_GFINDEX4D (const cGH *GH, int i, int j, int k, int l);
the linear index for the given spatial indices
@endreturndesc
@@*/
-int CCTK_GFINDEX1D (const cGH *GH, int i)
+int CCTK_GFIndex1D (const cGH *GH, int i)
{
GH = GH;
return (i);
}
-int CCTK_GFINDEX2D (const cGH *GH, int i, int j)
+int CCTK_GFIndex2D (const cGH *GH, int i, int j)
{
return (i + GH->cctk_lsh[0]*j);
}
-int CCTK_GFINDEX3D (const cGH *GH, int i, int j, int k)
+int CCTK_GFIndex3D (const cGH *GH, int i, int j, int k)
{
return (i + GH->cctk_lsh[0]*(j + GH->cctk_lsh[1]*k));
}
-int CCTK_GFINDEX4D (const cGH *GH, int i, int j, int k, int l)
+int CCTK_GFIndex4D (const cGH *GH, int i, int j, int k, int l)
{
return (i + GH->cctk_lsh[0]*(j + GH->cctk_lsh[1]*(k + GH->cctk_lsh[2] * l)));
}
-
-#endif /* CCTK_DEBUG */