From db43c0b72d1eb0dcf2778413743fcf355b5632a1 Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Tue, 15 Dec 2020 00:41:53 +0100 Subject: [PATCH] compiler.h: add host_build() Add a host_build() function, so that it's possible to check for software being build with USE_HOSTCC without relying on preprocessor conditions. In other words #ifdef USE_HOSTCC host_only_code(); #endif can be written like this instead: if (host_build()) host_only_code(); This improves code readability and test coverage and compiler will eleminate this unreachable code. Signed-off-by: Sebastian Reichel Reviewed-by: Simon Glass --- include/compiler.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/compiler.h b/include/compiler.h index 90b7afae53..27b9843497 100644 --- a/include/compiler.h +++ b/include/compiler.h @@ -6,6 +6,7 @@ #define __COMPILER_H__ #include +#include #ifdef USE_HOSTCC @@ -150,4 +151,12 @@ typedef unsigned long int uintptr_t; #define MEM_SUPPORT_64BIT_DATA 0 #endif +static inline bool host_build(void) { +#ifdef USE_HOSTCC + return true; +#else + return false; +#endif +} + #endif