From: Philipp Takacs Date: Thu, 21 Sep 2023 10:18:34 +0000 (+0200) Subject: add some gcc hint defines X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;h=b97368925e31edcfc6f69366d7b725e6a4d9881e;hp=b4a7a101560deabcd020021e3854fd0833cd4d90;p=mmh add some gcc hint defines The defines can help the compiler to produce better warnings and errors. This is manual cherrypicked from nmh --- diff --git a/h/mh.h b/h/mh.h index 649582d..88bcde5 100644 --- a/h/mh.h +++ b/h/mh.h @@ -38,8 +38,26 @@ typedef unsigned char boolean; /* not int so we can pack in a structure */ */ #if __GNUC__ > 2 # define NORETURN __attribute__((__noreturn__)) +# define CONST __attribute__((const)) +# define MALLOC __attribute__((malloc)) +# define NONNULL(...) __attribute__((nonnull(__VA_ARGS__))) +# define PURE __attribute__((pure)) +# define ENDNULL __attribute__((sentinel)) #else # define NORETURN +# define CONST +# define MALLOC +# define NONNULL(...) +# define PURE +# define ENDNULL +#endif + +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +# define ALLOC_SIZE(...) __attribute__((alloc_size(__VA_ARGS__))) +# define CHECK_PRINTF(fmt, arg) __attribute__((format(printf, fmt, arg))) +#else +# define ALLOC_SIZE(...) +# define CHECK_PRINTF(fmt, arg) #endif /*