From d03dd0c701efa586f17f9b1ffed7c6efaa80c82f Mon Sep 17 00:00:00 2001 From: Alison Watson Date: Mon, 25 Nov 2019 15:09:21 -0500 Subject: [PATCH] replace COMPILE_TIME_ASSERT with _Static_assert --- CMakeLists.txt | 4 ++-- source/net_sys.h | 12 ++++++------ source/q_stdinc.h | 37 ++++++------------------------------- source/snd_umx.c | 4 ++-- 4 files changed, 16 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 616b90d..1ccb358 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,7 +154,6 @@ set(srcs source/wad.h source/world.c source/world.h - source/wsaerror.h source/zone.c source/zone.h) @@ -166,7 +165,8 @@ if(WIN32) source/net_wipx.c source/net_wipx.h source/pl_win.c - source/sys_sdl_win.c) + source/sys_sdl_win.c + source/wsaerror.h) else() list(APPEND srcs source/net_bsd.c diff --git a/source/net_sys.h b/source/net_sys.h index 77727e3..9e996da 100644 --- a/source/net_sys.h +++ b/source/net_sys.h @@ -81,8 +81,8 @@ typedef int socklen_t; /* defining as signed int to match the old api */ #define socketerror(x) strerror((x)) -/* Verify that we defined HAVE_SA_LEN correctly: */ -COMPILE_TIME_ASSERT(sockaddr, offsetof(struct sockaddr, sa_family) == SA_FAM_OFFSET); +_Static_assert(offsetof(struct sockaddr, sa_family) == SA_FAM_OFFSET, + "HAVE_SA_LEN not defined correctly"); #endif /* end of unix stuff */ @@ -133,8 +133,8 @@ typedef unsigned int in_addr_t; /* u_int32_t */ /* there is h_errno but no hstrerror() */ #define hstrerror(x) strerror((x)) -/* Verify that we defined HAVE_SA_LEN correctly: */ -COMPILE_TIME_ASSERT(sockaddr, offsetof(struct sockaddr, sa_family) == SA_FAM_OFFSET); +_Static_assert(offsetof(struct sockaddr, sa_family) == SA_FAM_OFFSET, + "HAVE_SA_LEN not defined correctly"); #endif /* end of amiga bsdsocket.library stuff */ @@ -170,8 +170,8 @@ typedef SOCKET sys_socket_t; /* must #include "wsaerror.h" for this : */ #define socketerror(x) __WSAE_StrError((x)) -/* Verify that we defined HAVE_SA_LEN correctly: */ -COMPILE_TIME_ASSERT(sockaddr, offsetof(struct sockaddr, sa_family) == SA_FAM_OFFSET); +_Static_assert(offsetof(struct sockaddr, sa_family) == SA_FAM_OFFSET, + "HAVE_SA_LEN not defined correctly"); #endif /* end of windows stuff */ diff --git a/source/q_stdinc.h b/source/q_stdinc.h index 84e423d..5d7655a 100644 --- a/source/q_stdinc.h +++ b/source/q_stdinc.h @@ -67,14 +67,6 @@ /*==========================================================================*/ -#ifndef NULL -#if defined(__cplusplus) -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - #define Q_MAXCHAR ((char)0x7f) #define Q_MAXSHORT ((short)0x7fff) #define Q_MAXINT ((int)0x7fffffff) @@ -90,20 +82,17 @@ /* Make sure the types really have the right * sizes: These macros are from SDL headers. */ -#define COMPILE_TIME_ASSERT(name, x) \ - typedef int dummy_ ## name[(x) * 2 - 1] - -COMPILE_TIME_ASSERT(char, sizeof(char) == 1); -COMPILE_TIME_ASSERT(float, sizeof(float) == 4); -COMPILE_TIME_ASSERT(long, sizeof(long) >= 4); -COMPILE_TIME_ASSERT(int, sizeof(int) == 4); -COMPILE_TIME_ASSERT(short, sizeof(short) == 2); +_Static_assert(sizeof(char) == 1, "char not correct size"); +_Static_assert(sizeof(float) == 4, "float not correct size"); +_Static_assert(sizeof(long) >= 4, "long not correct size"); +_Static_assert(sizeof(int) == 4, "int not correct size"); +_Static_assert(sizeof(short) == 2, "short not correct size"); /* make sure enums are the size of ints for structure packing */ typedef enum { THE_DUMMY_VALUE } THE_DUMMY_ENUM; -COMPILE_TIME_ASSERT(enum, sizeof(THE_DUMMY_ENUM) == sizeof(int)); +_Static_assert(sizeof(THE_DUMMY_ENUM) == sizeof(int), "enum not sizeof(int)"); /* Provide a substitute for offsetof() if we don't have one. @@ -118,24 +107,10 @@ COMPILE_TIME_ASSERT(enum, sizeof(THE_DUMMY_ENUM) == sizeof(int)); typedef unsigned char byte; -#undef true -#undef false -#if defined(__cplusplus) -/* some structures have qboolean members and the x86 asm code expect - * those members to be 4 bytes long. therefore, qboolean must be 32 - * bits and it can NOT be binary compatible with the 8 bit C++ bool. */ -typedef int qboolean; -COMPILE_TIME_ASSERT(falsehood, (0 == false)); -COMPILE_TIME_ASSERT(truth, (1 == true)); -#else typedef enum { false = 0, true = 1 } qboolean; -COMPILE_TIME_ASSERT(falsehood, ((1 != 1) == false)); -COMPILE_TIME_ASSERT(truth, ((1 == 1) == true)); -#endif -COMPILE_TIME_ASSERT(qboolean, sizeof(qboolean) == 4); /*==========================================================================*/ diff --git a/source/snd_umx.c b/source/snd_umx.c index 7703cc3..0a7c2be 100644 --- a/source/snd_umx.c +++ b/source/snd_umx.c @@ -64,8 +64,8 @@ struct upkg_hdr { #define UPKG_HDR_SIZE 64 /* 64 bytes up until here */ /*struct _genhist *gen;*/ }; -/*COMPILE_TIME_ASSERT(upkg_hdr, offsetof(struct upkg_hdr, gen) == UPKG_HDR_SIZE);*/ -COMPILE_TIME_ASSERT(upkg_hdr, sizeof(struct upkg_hdr) == UPKG_HDR_SIZE); +_Static_assert(sizeof(struct upkg_hdr) == UPKG_HDR_SIZE, + "upkg_hdr not correct size"); #define UMUSIC_IT 0 #define UMUSIC_S3M 1