On 2020/4/22 下午4:26, Marek Behun wrote: > On Wed, 22 Apr 2020 14:49:46 +0800 > Qu Wenruo <[email protected]> wrote: > >> +/* A simple wraper to for error() from btrfs-progs */ >> +#define error(...) { printf(__VA_ARGS__); printf("\n"); } > > Is this from btrfs-progs?
Nope, anything in compat.h is mostly for different projects to share the
same code.
> I don't like these macros much, I prefer to use static inline functions.
>
> static inline void error(const char *fmt, ...)
> {
> printf(fmt, __builtin_va_arg_pack());
> printf("\n");
> }
That looks much better, especially we can tell compiler that we want
printf check on the parameters.
Thanks,
Qu
>
> Attribute for printf can be added to check printf specifiers:
> __attribute__((format (__printf__, 1, 2)))
>
> It is possible that this won't compile when optimizations are disabled.
> In that case more attributes are needed
> __always_inline __attribute__((__gnu_inline__))
> These could be defined as a macro in include/linux/compiler-gcc.h
> #define __gnu_inline __always_inline __attribute__((__gnu_inline__))
>
> Marek
>
signature.asc
Description: OpenPGP digital signature

