summaryrefslogtreecommitdiff
path: root/prism/compiler/format.h
blob: 32f4c3c6d7752349ce46944835aa7c241eecbea6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
 * @file compiler/format.h
 */
#ifndef PRISM_COMPILER_FORMAT_H
#define PRISM_COMPILER_FORMAT_H

/**
 * Certain compilers support specifying that a function accepts variadic
 * parameters that look like printf format strings to provide a better developer
 * experience when someone is using the function. This macro does that in a
 * compiler-agnostic way.
 */
#if defined(__GNUC__)
#   if defined(__MINGW_PRINTF_FORMAT)
#       define PRISM_ATTRIBUTE_FORMAT(fmt_idx_, arg_idx_) __attribute__((format(__MINGW_PRINTF_FORMAT, fmt_idx_, arg_idx_)))
#   else
#       define PRISM_ATTRIBUTE_FORMAT(fmt_idx_, arg_idx_) __attribute__((format(printf, fmt_idx_, arg_idx_)))
#   endif
#elif defined(__clang__)
#   define PRISM_ATTRIBUTE_FORMAT(fmt_idx_, arg_idx_) __attribute__((__format__(__printf__, fmt_idx_, arg_idx_)))
#else
#   define PRISM_ATTRIBUTE_FORMAT(fmt_idx_, arg_idx_)
#endif

#endif