mirror of
https://github.com/thepigeongenerator/sdl_template.git
synced 2025-12-18 06:25:47 +01:00
add more attributes
added a format and nonnull attribute in the attributes header. - convert original format attribute into the one used in the header (on prints) - use new nonnull attribute on prints as well
This commit is contained in:
12
src/error.h
12
src/error.h
@@ -3,6 +3,8 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdnoreturn.h>
|
#include <stdnoreturn.h>
|
||||||
|
|
||||||
|
#include "util/attributes.h"
|
||||||
|
|
||||||
/* defines statuses in the 0..127, any higher/negative values are POSIX-reserved.
|
/* defines statuses in the 0..127, any higher/negative values are POSIX-reserved.
|
||||||
* The max value (or -1) shall mean the application is running, anything else shall mean an exit code of some kind */
|
* The max value (or -1) shall mean the application is running, anything else shall mean an exit code of some kind */
|
||||||
enum {
|
enum {
|
||||||
@@ -28,10 +30,10 @@ enum {
|
|||||||
};
|
};
|
||||||
typedef int8_t gamestatus;
|
typedef int8_t gamestatus;
|
||||||
|
|
||||||
__attribute__((format(printf, 1, 2))) void debug(char const*, ...); // prints a debug message to stdout if the DEBUG environment variable is set, otherwise the call is ignored.
|
atrb_nonnull(1) atrb_format(printf, 1, 2) void debug(char const*, ...); // prints a debug message to stdout if the DEBUG environment variable is set, otherwise the call is ignored.
|
||||||
__attribute__((format(printf, 1, 2))) void info(char const*, ...); // prints an info message to stdout
|
atrb_nonnull(1) atrb_format(printf, 1, 2) void info(char const*, ...); // prints an info message to stdout
|
||||||
__attribute__((format(printf, 1, 2))) void warn(char const*, ...); // prints a warning message to stderr
|
atrb_nonnull(1) atrb_format(printf, 1, 2) void warn(char const*, ...); // prints a warning message to stderr
|
||||||
__attribute__((format(printf, 1, 2))) void error(char const*, ...); // prints an warning message to stderr
|
atrb_nonnull(1) atrb_format(printf, 1, 2) void error(char const*, ...); // prints an warning message to stderr
|
||||||
|
|
||||||
// prints an error message to stderr before exiting
|
// prints an error message to stderr before exiting
|
||||||
__attribute__((format(printf, 4, 5))) noreturn void fatal(gamestatus, char const* file_name, uint32_t line, char const* fmt, ...);
|
atrb_nonnull(2, 4) atrb_format(printf, 4, 5) noreturn void fatal(gamestatus, char const* file_name, uint32_t line, char const* fmt, ...);
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
#define atrb_unused
|
#define atrb_unused
|
||||||
#define atrb_pure
|
#define atrb_pure
|
||||||
#define atrb_const
|
#define atrb_const
|
||||||
|
#define atrb_format()
|
||||||
|
#define atrb_nonnull()
|
||||||
|
|
||||||
// define the attributes where possible
|
// define the attributes where possible
|
||||||
#if defined(__GNUC__) || defined(__clang__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
@@ -25,10 +27,21 @@
|
|||||||
# define atrb_pure __attribute__((pure))
|
# define atrb_pure __attribute__((pure))
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
|
||||||
# if __has_attribute(const)
|
# if __has_attribute(const)
|
||||||
# undef atrb_const
|
# undef atrb_const
|
||||||
# define atrb_const __attribute__((const))
|
# define atrb_const __attribute__((const))
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# if __has_attribute(format)
|
||||||
|
# undef atrb_format
|
||||||
|
# define atrb_format(...) __attribute__((format(__VA_ARGS__)))
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# if __has_attribute(nonnull)
|
||||||
|
# undef atrb_nonnull
|
||||||
|
# define atrb_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))
|
||||||
|
# endif
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
# undef atrb_depatrb_deprecated
|
# undef atrb_depatrb_deprecated
|
||||||
# define atrb_deprecated __declspec(deprecated)
|
# define atrb_deprecated __declspec(deprecated)
|
||||||
|
|||||||
Reference in New Issue
Block a user