From 481018f2804065cb5ed1cde75b7c0596aeef959a Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 25 Mar 2019 09:35:29 +0100 Subject: Add macro to cast away volatile without allowing changes to underlying type This adds unvolatize(), which works just like unconstify() but for volatile. Discussion: https://www.postgresql.org/message-id/flat/7a5cbea7-b8df-e910-0f10-04014bcad701%402ndquadrant.com --- src/include/c.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/include/c.h') diff --git a/src/include/c.h b/src/include/c.h index 658be50e0d..33c9518195 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -1122,7 +1122,7 @@ typedef union PGAlignedXLogBlock #endif /* - * Macro that allows to cast constness away from an expression, but doesn't + * Macro that allows to cast constness and volatile away from an expression, but doesn't * allow changing the underlying type. Enforcement of the latter * currently only works for gcc like compilers. * @@ -1141,9 +1141,15 @@ typedef union PGAlignedXLogBlock (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), const underlying_type), \ "wrong cast"), \ (underlying_type) (expr)) +#define unvolatize(underlying_type, expr) \ + (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), volatile underlying_type), \ + "wrong cast"), \ + (underlying_type) (expr)) #else #define unconstify(underlying_type, expr) \ ((underlying_type) (expr)) +#define unvolatize(underlying_type, expr) \ + ((underlying_type) (expr)) #endif /* ---------------------------------------------------------------- -- cgit v1.2.3