/* Copyright 2020, Dirk Krause. All rights reserved. SPDX-License-Identifier: BSD-3-Clause */ #ifndef DK4UNUSED_H_INCLUDED /** @file dk4unused.h Mark function arguments as unused by intent. */ /** Protection against multiple inclusions. */ #define DK4UNUSED_H_INCLUDED 1 #ifndef DK4CONF_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4conf.h" #else #include #endif #endif /* Unused arguments can occur in callback functions which must follow a given prototype. ------------------------------------------------------ */ #if DK4_HAVE_ATTRIBUTE_UNUSED /** Mark function argument x as intentionally unused. */ #define DK4_ARG_UNUSED(x) x __attribute__((unused)) #else /** Mark function argument x as intentionally unused. */ #define DK4_ARG_UNUSED(x) x #endif /* For some functions I used an equal style prototype. There is no need for the unused arguments in the prototype. Removing the unused arguments from the function declaration would mean removing the appropriate arguments from all function calls. The involved arguments are typically items in lists of same type arguments. Accidently removing a wrong argument from the call would not result in compiler warnings, so there would be a high risk of introducing new bugs. ---------------------------------------------------------------------- */ #if DK4_HAVE_ATTRIBUTE_UNUSED /** Mark function argument x as intentionally unused. */ #define DK4_SILENCE_ARG_UNUSED(x) x __attribute__((unused)) #else /** Mark function argument x as intentionally unused. */ #define DK4_SILENCE_ARG_UNUSED(x) x #endif #if DK4_HAVE_ATTRIBUTE_UNUSED /** Mark variable x as intentionally unused. */ #define DK4_VAR_UNUSED(x) x __attribute__((unused)) #else #if defined(_MSC_VER) && (_MSC_VER >= 1700) /** Mark variable x as intentionally unused. */ #define DK4_VAR_UNUSED(x) __pragma(warning(suppress: 4100)) x #else /** Mark variable x as intentionally unused. */ #define DK4_VAR_UNUSED(x) x #endif #endif #if DK4_HAVE_ATTRIBUTE_UNUSED /** Do anything with an unused function argument to suppress compiler warnings. */ #define DK4_UNUSED_ARG(x) #else /** Do anything with an unused function argument to suppress compiler warnings. */ #if (_WIN32) && defined(_MSC_VER) /* define DK4_UNUSED_ARG(x) UNREFERENCED_PARAMETER(x); */ #define DK4_UNUSED_ARG(x) (void)(x); #else #define DK4_UNUSED_ARG(x) (void)(x); #endif #endif #endif