util: use __typeof__ instead of typeof

'typeof' is a GNU extension - let's use __typeof__
instead which is ISO C compliant.

Allows building SPDK header files with -std=c11 as
long as _GNU_SOURCE is also defined.

Next patch will enable omitting _GNU_SOURCE as well.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: Ibd6c984627b553d6f87f302800abc52157fe9b1e
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8332
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Jacek Kalwas <jacek.kalwas@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
This commit is contained in:
Jim Harris 2021-06-14 14:46:14 +00:00 committed by Tomasz Zawadzki
parent 74c88aa62b
commit f29acca244

View File

@ -66,7 +66,7 @@ extern "C" {
* power-of-two value.
*/
#define SPDK_ALIGN_FLOOR(val, align) \
(typeof(val))((val) & (~((typeof(val))((align) - 1))))
(__typeof__(val))((val) & (~((__typeof__(val))((align) - 1))))
/**
* Macro to align a value to a given power-of-two. The resultant value
* will be of the same type as the first parameter, and will be no lower
@ -74,7 +74,7 @@ extern "C" {
* value.
*/
#define SPDK_ALIGN_CEIL(val, align) \
SPDK_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align)
SPDK_ALIGN_FLOOR(((val) + ((__typeof__(val)) (align) - 1)), align)
uint32_t spdk_u32log2(uint32_t x);