[DTrace-devel] [PATCH v3 05/21] compiler: add static assertions

Kris Van Hees kris.van.hees at oracle.com
Thu Feb 15 02:08:18 UTC 2024


I am reconsidering this because as it turns out, there is exactly 1 use of this
in the entire DTrace codebase.  Even the >8k lines of patches in this patch
series only introduces that single instance of a static assertion.  Maybe this
should just wait until a time where someone might perhaps go through the code
base and introduce static assertions where possible (if there are enough of
them to even bother)?

On Tue, Jan 16, 2024 at 09:13:01PM +0000, Nick Alcock via DTrace-devel wrote:
> C11 provides static assertions, and some compilers provide them even before
> C11: so allow them to be used if available, to get earlier warning of
> compile-time problems.
> 
> Signed-off-by: Nick Alcock <nick.alcock at oracle.com>
> Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>
> ---
>  include/sys/compiler.h | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/include/sys/compiler.h b/include/sys/compiler.h
> index 82066e5e48d5..766a955346e8 100644
> --- a/include/sys/compiler.h
> +++ b/include/sys/compiler.h
> @@ -8,6 +8,8 @@
>  #ifndef _SYS_COMPILER_H
>  #define _SYS_COMPILER_H
>  
> +#include <assert.h>
> +
>  /*
>   * Attributes that vary on a compiler-by-compiler basis.
>   */
> @@ -56,4 +58,11 @@
>  #define _dt_unused_
>  
>  #endif
> +
> +/* < C11? turn static assertions into ordinary assertions.  */
> +
> +#if (!defined (__STDC_VERSION__) || __STDC_VERSION__ < 201112L) && !defined(_Static_assert)
> +#define _Static_assert(cond, err) assert(cond)
> +#endif
> +
>  #endif
> -- 
> 2.43.0.272.gce700b77fd
> 
> 
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel



More information about the DTrace-devel mailing list