diff --git a/scripts/unused-macro.cocci b/scripts/unused-macro.cocci
new file mode 100644
index 0000000000000000000000000000000000000000..47f0fccc58af79f64cd9cf7a140b3ab13522a94f
--- /dev/null
+++ b/scripts/unused-macro.cocci
@@ -0,0 +1,11 @@
+//
+// Use UNUSED(var) macro instead of casting expression to void.
+//
+
+@@
+expression E;
+@@
+(
+-(void)E;
++UNUSED(E);
+)
diff --git a/src/common/libtap/tap.c b/src/common/libtap/tap.c
index ada89071ff350a278fd9dbb691f9b20b7f243db7..e89948b8de0d5c65f31074568f58a22b27132dca 100644
--- a/src/common/libtap/tap.c
+++ b/src/common/libtap/tap.c
@@ -9,6 +9,7 @@ This file is licensed under the GPL v3
 #include <stdlib.h>
 #include <stdarg.h>
 #include <string.h>
+#include "common.h"
 #include "tap.h"
 
 static int expected_tests = NO_PLAN;
@@ -226,7 +227,7 @@ exit_status () {
 
 int
 bail_out (int ignore, const char *fmt, ...) {
-    (void)ignore;
+    UNUSED(ignore);
     va_list args;
     va_start(args, fmt);
     printf("Bail out!  ");
@@ -253,7 +254,7 @@ skippy (int n, const char *fmt, ...) {
 
 void
 ctodo (int ignore, const char *fmt, ...) {
-    (void)ignore;
+    UNUSED(ignore);
     va_list args;
     va_start(args, fmt);
     todo_mesg = vstrdupf(fmt, args);
diff --git a/src/common/mempattern.c b/src/common/mempattern.c
index 456ac7d3508bc42aa2418d21b2dd9e241060de7b..2ea7e5044e5202c59a6b215355da2ec6ec05d793 100644
--- a/src/common/mempattern.c
+++ b/src/common/mempattern.c
@@ -27,7 +27,7 @@
 
 static void *mm_malloc(void *ctx, size_t n)
 {
-	(void)ctx;
+	UNUSED(ctx);
 	return malloc(n);
 }
 
diff --git a/src/common/mempattern.h b/src/common/mempattern.h
index de77c063d6eb33a88606ffcb57f434fe142058da..7bef8513616633dfcbcff69a692b9d9b64d7223a 100644
--- a/src/common/mempattern.h
+++ b/src/common/mempattern.h
@@ -27,6 +27,8 @@
 #ifndef _KNOTD_COMMON_MALLOC_H_
 #define _KNOTD_COMMON_MALLOC_H_
 
+#include <stddef.h>
+
 /* Memory allocation function prototypes. */
 typedef void* (*mm_alloc_t)(void* ctx, size_t len);
 typedef void (*mm_free_t)(void *p);
diff --git a/src/common/prng.c b/src/common/prng.c
index eac134714071bfba430d094e6de5c082bb0d7c47..c94bd25eab9c75358588adf58bccf4a19247e9f0 100644
--- a/src/common/prng.c
+++ b/src/common/prng.c
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #endif
 
+#include "common.h"
 #include "prng.h"
 #include "dSFMT.h"
 
@@ -41,19 +42,19 @@ static void tls_prng_deinit(void *ptr)
 static void tls_prng_deinit_main()
 {
 	tls_prng_deinit(pthread_getspecific(tls_prng_key));
-	(void)pthread_setspecific(tls_prng_key, NULL);
+	UNUSED(pthread_setspecific(tls_prng_key, NULL));
 }
 
 static void tls_prng_init()
 {
-	(void) pthread_key_create(&tls_prng_key, tls_prng_deinit);
+	UNUSED(pthread_key_create(&tls_prng_key, tls_prng_deinit));
 	atexit(tls_prng_deinit_main); // Main thread cleanup
 }
 
 double tls_rand()
 {
 	/* Setup PRNG state for current thread. */
-	(void)pthread_once(&tls_prng_once, tls_prng_init);
+	UNUSED(pthread_once(&tls_prng_once, tls_prng_init));
 
 	/* Create PRNG state if not exists. */
 	dsfmt_t* s = pthread_getspecific(tls_prng_key);
@@ -97,7 +98,7 @@ double tls_rand()
 		}
 #endif
 		dsfmt_init_gen_rand(s, seed);
-		(void)pthread_setspecific(tls_prng_key, s);
+		UNUSED(pthread_setspecific(tls_prng_key, s));
 	}
 
 	return dsfmt_genrand_close_open(s);
diff --git a/src/common/queue.c b/src/common/queue.c
index 518c08244ffa65152590f38d3bb89b96cd7a9cbf..588c85e1b45ee92e37f822da64cab1940c545d17 100644
--- a/src/common/queue.c
+++ b/src/common/queue.c
@@ -22,6 +22,7 @@
  */
 
 #include <config.h>
+#include "common.h"
 #include "queue.h"
 #include "atomic.h"
 #include <stdbool.h>
@@ -43,7 +44,7 @@ static void sleep_consumer(struct queue *q)
 
 static void sleep_producer(struct queue *q)
 {
-	(void)q;
+	UNUSED(q);
 	/* sleep_consumer(q); */
 }
 
@@ -56,7 +57,7 @@ static void wake_consumer(struct queue *q)
 
 static void wake_producer(struct queue *q)
 {
-	(void)q;
+	UNUSED(q);
 	/* wake_consumer(q); */
 }
 
diff --git a/src/common/slab/slab.c b/src/common/slab/slab.c
index dfd4b767657bee33ecf6962944d319e3b38b69b7..e5f9f9a7da884e3a51b8d6ec0f14d8ae7c25594e 100644
--- a/src/common/slab/slab.c
+++ b/src/common/slab/slab.c
@@ -91,14 +91,14 @@ static void* slab_depot_alloc(size_t bufsize)
 
 	}
 #else // MEM_SLAB_DEPOT
-	(void)bufsize;
+	UNUSED(bufsize);
 	if(posix_memalign(&page, SLAB_SZ, SLAB_SZ) == 0) {
 		((slab_t*)page)->bufsize = 0;
 	} else {
 		page = 0;
 	}
 #endif // MEM_SLAB_DEPOT
-	(void)bufsize;
+	UNUSED(bufsize);
 
 	return page;
 }
diff --git a/src/knot/server/zones.c b/src/knot/server/zones.c
index 981a9a66e0907166e88a85ba9ee0251112f58493..cfd7e321e576fd458663f3c0f8877ec2a1742de4 100644
--- a/src/knot/server/zones.c
+++ b/src/knot/server/zones.c
@@ -1855,7 +1855,7 @@ int zones_update_db_from_config(const conf_t *conf, knot_nameserver_t *ns,
 	                 "new db: %p\n", ns->zone_db, *db_old, db_new);
 
 	/* Switch the databases. */
-	(void)rcu_xchg_pointer(&ns->zone_db, db_new);
+	UNUSED(rcu_xchg_pointer(&ns->zone_db, db_new));
 
 	dbg_zones_detail("db in nameserver: %p, old db stored: %p, new db: %p\n",
 	                 ns->zone_db, *db_old, db_new);
@@ -2578,7 +2578,7 @@ static int zones_open_free_filename(const char *old_name, char **new_name)
 	dbg_zones_verb("zones: creating temporary zone file\n");
 	mode_t old_mode = umask(077);
 	int fd = mkstemp(*new_name);
-	(void) umask(old_mode);
+	UNUSED(umask(old_mode));
 	if (fd < 0) {
 		dbg_zones_verb("zones: couldn't create temporary zone file\n");
 		free(*new_name);
diff --git a/src/libknot/sign/dnssec.c b/src/libknot/sign/dnssec.c
index de7058ddbcbd29fd08b1208420de72d1ff56d8ef..ed9a652344ef70693bc8a2530afe8a1d8262d733 100644
--- a/src/libknot/sign/dnssec.c
+++ b/src/libknot/sign/dnssec.c
@@ -15,6 +15,7 @@
 */
 
 #include <config.h>
+#include "common.h"
 #include "common/descriptor.h"
 #include "common/errcode.h"
 #include "sign/bnutils.h"
@@ -243,7 +244,7 @@ static int dsa_create_pkey(const knot_key_params_t *params, EVP_PKEY *key)
  */
 static size_t dsa_sign_size(const knot_dnssec_key_t *key)
 {
-	(void)key;
+	UNUSED(key);
 	// RFC 2536 (section 3 - DSA SIG Resource Record)
 	return 41;
 }
diff --git a/src/libknot/updates/ddns.c b/src/libknot/updates/ddns.c
index d81ec72615ece9fcba141a8cdcb2d466db705694..7f4f14fc58609b5a1eef1c1ea8072052f92d43fa 100644
--- a/src/libknot/updates/ddns.c
+++ b/src/libknot/updates/ddns.c
@@ -1018,7 +1018,7 @@ static int knot_ddns_process_add_cname(knot_node_t *node,
 		}
 
 		/* c) And remove it from the node. */
-		(void)knot_node_remove_rrset(node, KNOT_RRTYPE_CNAME);
+		UNUSED(knot_node_remove_rrset(node, KNOT_RRTYPE_CNAME));
 
 		/* d) Check if this CNAME was not previously added by
 		 *    the UPDATE. If yes, remove it from the ADD
@@ -1132,7 +1132,7 @@ static int knot_ddns_process_add_soa(knot_node_t *node,
 		}
 
 		/* 2) And remove it from the node. */
-		(void)knot_node_remove_rrset(node, KNOT_RRTYPE_SOA);
+		UNUSED(knot_node_remove_rrset(node, KNOT_RRTYPE_SOA));
 
 		/* No changeset processing needed in this case. */
 	} else {