Generalize our process spawning code.
[metze/wireshark/wip.git] / ws_attributes.h
1 /* ws_attributes.h
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 1998 Gerald Combs
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9
10 #ifndef __WS_ATTRIBUTES_H__
11 #define __WS_ATTRIBUTES_H__
12
13 #include "ws_compiler_tests.h"
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif /* __cplusplus */
18
19 /*
20  * If we're running GCC or clang define _U_ to be "__attribute__((unused))"
21  * so we can use _U_ to flag unused function parameters and not get warnings
22  * about them. Otherwise, define _U_ to be an empty string so that _U_ used
23  * to flag an unused function parameters will compile with other compilers.
24  *
25  * XXX - similar hints for other compilers?
26  */
27 #if defined(__GNUC__)
28   /* This includes clang */
29   #define _U_ __attribute__((unused))
30 #else
31   #define _U_
32 #endif
33
34 /*
35  * WS_NORETURN, before a function declaration, means "this function
36  * never returns".  (It must go before the function declaration, e.g.
37  * "extern WS_NORETURN func(...)" rather than after the function
38  * declaration, as the MSVC version has to go before the declaration.)
39  */
40 #if __has_attribute(noreturn) \
41     || WS_IS_AT_LEAST_GNUC_VERSION(2,5) \
42     || WS_IS_AT_LEAST_SUNC_VERSION(5,9) \
43     || WS_IS_AT_LEAST_XL_C_VERSION(10,1) \
44     || WS_IS_AT_LEAST_HP_C_VERSION(6,10)
45   /*
46    * Compiler with support for __attribute__((noreturn)), or GCC 2.5 and
47    * later, or Solaris Studio 12 (Sun C 5.9) and later, or IBM XL C 10.1
48    * and later (do any earlier versions of XL C support this?), or
49    * HP aCC A.06.10 and later.
50    */
51   #define WS_NORETURN __attribute__((noreturn))
52 #elif defined(_MSC_VER)
53   /*
54    * MSVC.
55    */
56   #define WS_NORETURN __declspec(noreturn)
57 #else
58   #define WS_NORETURN
59 #endif
60
61 /*
62  * WS_RETNONNULL, before a function declaration, means "this function
63  * always returns a non-null pointer".
64  */
65 #if __has_attribute(returns_nonnull) \
66     || WS_IS_AT_LEAST_GNUC_VERSION(4,9)
67   #define WS_RETNONNULL __attribute__((returns_nonnull))
68 #else
69   #define WS_RETNONNULL
70 #endif
71
72 #ifdef __cplusplus
73 }
74 #endif /* __cplusplus */
75
76 #endif /* __WS_ATTRIBUTES_H__ */