diff --git a/config.c b/config.c index 74d47db8..64caa4ab 100644 --- a/config.c +++ b/config.c @@ -20,6 +20,7 @@ #define LOG_ENABLE_DBG 0 #include "log.h" #include "input.h" +#include "macros.h" #include "tokenize.h" #include "util.h" #include "wayland.h" @@ -1111,7 +1112,7 @@ parse_config_file(FILE *f, struct config *conf, const char *path, bool errors_ar /* Split up into key/value pair + trailing comment */ char *key_value = strtok(line, "#"); - char *comment __attribute__((unused)) = strtok(NULL, "\n"); + char UNUSED *comment = strtok(NULL, "\n"); /* Check for new section */ if (key_value[0] == '[') { diff --git a/input.c b/input.c index 645fa4b3..9c94e2ba 100644 --- a/input.c +++ b/input.c @@ -26,6 +26,7 @@ #include "config.h" #include "commands.h" #include "keymap.h" +#include "macros.h" #include "quirks.h" #include "render.h" #include "search.h" @@ -1116,8 +1117,7 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, } else { if (surface != NULL) { /* Sway 1.4 sends this event with a NULL surface when we destroy the window */ - const struct wl_window *win __attribute__((unused)) - = wl_surface_get_user_data(surface); + const struct wl_window UNUSED *win = wl_surface_get_user_data(surface); assert(old_moused == win->term); } diff --git a/log.c b/log.c index eff6992d..d47e22ac 100644 --- a/log.c +++ b/log.c @@ -79,8 +79,7 @@ _log(enum log_class log_class, const char *module, const char *file, int lineno, static void _sys_log(enum log_class log_class, const char *module, - const char *file __attribute__((unused)), - int lineno __attribute__((unused)), + const char UNUSED *file, int UNUSED lineno, const char *fmt, int sys_errno, va_list va) { if (!do_syslog) diff --git a/log.h b/log.h index dfddd765..34713d2a 100644 --- a/log.h +++ b/log.h @@ -1,5 +1,6 @@ #pragma once #include +#include "macros.h" enum log_colorize { LOG_COLORIZE_NEVER, LOG_COLORIZE_ALWAYS, LOG_COLORIZE_AUTO }; enum log_facility { LOG_FACILITY_USER, LOG_FACILITY_DAEMON }; @@ -11,16 +12,16 @@ void log_deinit(void); void log_msg(enum log_class log_class, const char *module, const char *file, int lineno, - const char *fmt, ...) __attribute__((format (printf, 5, 6))); + const char *fmt, ...) PRINTF(5); void log_errno(enum log_class log_class, const char *module, const char *file, int lineno, - const char *fmt, ...) __attribute__((format (printf, 5, 6))); + const char *fmt, ...) PRINTF(5); void log_errno_provided( enum log_class log_class, const char *module, const char *file, int lineno, int _errno, - const char *fmt, ...) __attribute__((format (printf, 6, 7))); + const char *fmt, ...) PRINTF(6); #define LOG_ERR(fmt, ...) \ log_msg(LOG_CLASS_ERROR, LOG_MODULE, __FILE__, __LINE__, fmt, ## __VA_ARGS__) diff --git a/macros.h b/macros.h index c8990858..323b3748 100644 --- a/macros.h +++ b/macros.h @@ -20,6 +20,12 @@ #define HAS_BUILTIN(x) 0 #endif +#if GNUC_AT_LEAST(3, 0) || HAS_ATTRIBUTE(unused) || defined(__TINYC__) + #define UNUSED __attribute__((__unused__)) +#else + #define UNUSED +#endif + #if GNUC_AT_LEAST(3, 0) || HAS_ATTRIBUTE(malloc) #define MALLOC __attribute__((__malloc__)) #else diff --git a/shm.c b/shm.c index 260694f6..317bc9c9 100644 --- a/shm.c +++ b/shm.c @@ -22,6 +22,7 @@ #define LOG_MODULE "shm" #define LOG_ENABLE_DBG 0 #include "log.h" +#include "macros.h" #define TIME_SCROLL 0 @@ -398,7 +399,7 @@ static bool wrap_buffer(struct wl_shm *shm, struct buffer *buf, off_t new_offset) { /* We don't allow overlapping offsets */ - off_t diff __attribute__((unused)) = + off_t UNUSED diff = new_offset < buf->offset ? buf->offset - new_offset : new_offset - buf->offset; assert(diff > buf->size); diff --git a/terminal.c b/terminal.c index 55ea840e..900f8fae 100644 --- a/terminal.c +++ b/terminal.c @@ -1032,7 +1032,7 @@ fdm_shutdown(struct fdm *fdm, int fd, int events, void *data) wayl_win_destroy(term->window); term->window = NULL; - struct wayland *wayl __attribute__((unused)) = term->wl; + struct wayland *wayl = term->wl; /* * Normally we'd get unmapped when we destroy the Wayland