subsurface/core/format.h
Berthold Stoeger 322c3b55e6 core: add compile time format check to format_string_std
Had to rewrite the thing, because gcc's warnings don't work
with templatized var-args. Since there is no string-format.cpp
and I didn't want to inline it, moved it to format.cpp.

String formatting is distributed around at least four
headers: membuffer.h, subsurface-string.h, format.h
and format-string.h. This really should be unified!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-04-23 07:47:11 +07:00

33 lines
878 B
C++

#ifndef FORMAT_H
#define FORMAT_H
#ifdef __GNUC__
#define __printf(x, y) __attribute__((__format__(__printf__, x, y)))
#else
#define __printf(x, y)
#endif
#ifdef __cplusplus
#include <QString>
__printf(1, 2) QString qasprintf_loc(const char *cformat, ...);
__printf(1, 0) QString vqasprintf_loc(const char *cformat, va_list ap);
__printf(1, 2) std::string casprintf_loc(const char *cformat, ...);
#endif
#ifdef __cplusplus
extern "C" {
#endif
__printf(3, 4) int snprintf_loc(char *dst, size_t size, const char *cformat, ...);
__printf(3, 0) int vsnprintf_loc(char *dst, size_t size, const char *cformat, va_list ap);
__printf(2, 3) int asprintf_loc(char **dst, const char *cformat, ...);
__printf(2, 0) int vasprintf_loc(char **dst, const char *cformat, va_list ap);
#ifdef __cplusplus
}
__printf(1, 2) std::string format_string_std(const char *fmt, ...);
#endif
#endif