summaryrefslogtreecommitdiff
path: root/src/include/cctk_Types.h
diff options
context:
space:
mode:
authorschnetter <schnetter@17b73243-c579-4c4c-a9d2-2d5706c11dac>2005-09-26 00:21:00 +0000
committerschnetter <schnetter@17b73243-c579-4c4c-a9d2-2d5706c11dac>2005-09-26 00:21:00 +0000
commita1492b067055e73d5b61dfe45c3cd4200bee64a2 (patch)
treef0677049f29bd0d18f50337523989fc8a1c563ac /src/include/cctk_Types.h
parent06d94fb1dae1bedc506b432ccb1157d6aaa874d8 (diff)
Introduce macros CCTK_DECLARE and CCTK_DECLARE_INIT which declare or
declare and initialise local variables. They also add the necessary magic to prevent compiler warnings about unused variables. If the compiler supports __attribute__((unused)), then use this. Otherwise, use the existing fallback of taking the variable's address. In Fortran, use the variable's kind as fallback. Use these macros in autogenerated code and in "cctk.h". git-svn-id: http://svn.cactuscode.org/flesh/trunk@4146 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/include/cctk_Types.h')
-rw-r--r--src/include/cctk_Types.h56
1 files changed, 55 insertions, 1 deletions
diff --git a/src/include/cctk_Types.h b/src/include/cctk_Types.h
index 8405b3f3..1b50fada 100644
--- a/src/include/cctk_Types.h
+++ b/src/include/cctk_Types.h
@@ -21,6 +21,33 @@
/* Define stuff for C. */
#ifdef CCODE
+
+/* Declare and initialise a variable and tell the compiler that it may
+ be unused. This is used for CCTK_PARAMETERS and CCTK_ARGUMENTS.
+
+ The macro CCTK_DECLARE_INIT (typ, nam, val) is used with
+ typ: a type, used to declare the variable (e.g. "const int")
+ nam: the variable name (e.g. "x")
+ val: the value used to initialise it (e.g. "42")
+*/
+
+#if (! __cplusplus && HAVE_CCTK_C_ATTRIBUTE_UNUSED ) \
+ || ( __cplusplus && HAVE_CCTK_CXX_ATTRIBUTE_UNUSED)
+
+/* We have __attribute__((unused)), so use it */
+#define CCTK_DECLARE_INIT(typ,nam,val) \
+ typ nam __attribute__((unused)) = (val);
+
+#else
+
+/* Some fallback, bound to fool most compilers */
+#define CCTK_DECLARE_INIT(typ,nam,val) \
+ typ nam = (val); \
+ void const * cctki_use_##nam = (cctki_use_##nam = &nam, &cctki_use_##nam);
+
+#endif
+
+
typedef void *CCTK_POINTER;
typedef const void *CCTK_POINTER_TO_CONST;
typedef void (*CCTK_FPOINTER)(void);
@@ -63,9 +90,36 @@ typedef unsigned char CCTK_BYTE;
#endif /* CCODE */
-/* Define stuff for fortran. */
+/* Define stuff for Fortran. */
#ifdef FCODE
+
+/* Declare a variable and tell the compiler that it may be unused.
+ This is used for CCTK_ARGUMENTS.
+
+ The macro CCTK_DECLARE (typ, nam, dim) is used with
+ typ: a type, used to declare the variable (e.g. "CCTK_REAL")
+ nam: the variable name (e.g. "x")
+ dim: optional array dimensions, (e.g. "(10,10)")
+*/
+
+#ifdef F90CODE
+
+/* Declare it, and use it for a dummy operation */
+#define CCTK_DECLARE(typ,nam,dim) \
+ typ nam dim && \
+ integer, parameter :: cctki_use_/**/nam = kind(nam)
+
+#else
+
+/* Just declare it; FORTRAN 77 has no good way of marking it as used
+ within a block of declarations */
+#define CCTK_DECLARE(typ,nam,dim) \
+ typ nam dim
+
+#endif
+
+
#define CCTK_POINTER integer*SIZEOF_CHAR_P
#define CCTK_POINTER_TO_CONST integer*SIZEOF_CHAR_P
/* TODO: add autoconf for determining the size of function pointers */