Add CONST_CAST macro, for casting away "const" more safely.
[pspp-builds.git] / src / libpspp / cast.h
index 30927899c8bfb81dee56d509d16d7a5a3a72f52e..1e33857c1e3afa0a879512378df55694ca3900bc 100644 (file)
    above, can easily be devised. */
 #define CHECK_POINTER_COMPATIBILITY(A, B) ((void) sizeof ((A) == (B)))
 
+/* Equivalent to casting POINTER to TYPE, but also issues a
+   warning if the cast changes anything other than an outermost
+   "const" or "volatile" qualifier. */
+#define CONST_CAST(TYPE, POINTER)                       \
+        (CHECK_POINTER_HAS_TYPE (POINTER, TYPE),        \
+         (TYPE) (POINTER))
+
 /* Given POINTER, a pointer to the given MEMBER within structure
    STRUCT, returns the address of the STRUCT. */
 #define UP_CAST(POINTER, STRUCT, MEMBER)                                \