1 /*
2 Copyright 2020, Dirk Krause. All rights reserved.
3 SPDX-License-Identifier:	BSD-3-Clause
4 */
5 
6 #ifndef	DK4UNUSED_H_INCLUDED
7 
8 /**	@file	dk4unused.h	Mark function arguments as unused by intent.
9 */
10 
11 /**	Protection against multiple inclusions.
12 */
13 #define	DK4UNUSED_H_INCLUDED 1
14 
15 #ifndef	DK4CONF_H_INCLUDED
16 #if DK4_BUILDING_DKTOOLS4
17 #include "dk4conf.h"
18 #else
19 #include <dktools-4/dk4conf.h>
20 #endif
21 #endif
22 
23 
24 
25 /*
26 	Unused arguments can occur in callback functions which
27 	must follow a given prototype.
28 	------------------------------------------------------
29 */
30 
31 #if	DK4_HAVE_ATTRIBUTE_UNUSED
32 /**	Mark function argument x as intentionally unused.
33 */
34 #define	DK4_ARG_UNUSED(x) x __attribute__((unused))
35 #else
36 /**	Mark function argument x as intentionally unused.
37 */
38 #define	DK4_ARG_UNUSED(x) x
39 #endif
40 
41 
42 
43 /*
44 	For some functions I used an equal style prototype.
45 	There is no need for the unused arguments in the prototype.
46 	Removing the unused arguments from the function declaration would mean
47 	removing the appropriate arguments from all function calls.
48 	The involved arguments are typically items in lists of same type
49 	arguments.
50 	Accidently removing a wrong argument from the call would not result in
51 	compiler warnings, so there would be a high risk of introducing
52 	new bugs.
53 	----------------------------------------------------------------------
54 */
55 
56 #if	DK4_HAVE_ATTRIBUTE_UNUSED
57 /**	Mark function argument x as intentionally unused.
58 */
59 #define	DK4_SILENCE_ARG_UNUSED(x) x __attribute__((unused))
60 #else
61 /**	Mark function argument x as intentionally unused.
62 */
63 #define	DK4_SILENCE_ARG_UNUSED(x) x
64 #endif
65 
66 
67 #if	DK4_HAVE_ATTRIBUTE_UNUSED
68 /**	Mark variable x as intentionally unused.
69 */
70 #define	DK4_VAR_UNUSED(x) x __attribute__((unused))
71 #else
72 #if defined(_MSC_VER) && (_MSC_VER >= 1700)
73 /**	Mark variable x as intentionally unused.
74 */
75 #define DK4_VAR_UNUSED(x) __pragma(warning(suppress: 4100)) x
76 #else
77 /**	Mark variable x as intentionally unused.
78 */
79 #define	DK4_VAR_UNUSED(x) x
80 #endif
81 #endif
82 
83 
84 
85 #if	DK4_HAVE_ATTRIBUTE_UNUSED
86 /**	Do anything with an unused function argument to suppress compiler
87 	warnings.
88 */
89 #define	DK4_UNUSED_ARG(x)
90 #else
91 /**	Do anything with an unused function argument to suppress compiler
92 	warnings.
93 */
94 #if (_WIN32) && defined(_MSC_VER)
95 /* define	DK4_UNUSED_ARG(x) UNREFERENCED_PARAMETER(x); */
96 #define	DK4_UNUSED_ARG(x) (void)(x);
97 #else
98 #define	DK4_UNUSED_ARG(x) (void)(x);
99 #endif
100 #endif
101 
102 
103 
104 #endif
105