KronkNet 1.0
Loading...
Searching...
No Matches
optimization.h
1/*
2** FREE PROJECT, 2026
3** KRONKNET
4** File description:
5** Portability macros for compiler-specific attributes.
6*/
7
8#ifndef KRONKNET_MACROS_OPTIMIZATION_H
9 #define KRONKNET_MACROS_OPTIMIZATION_H
10
11 // NOTE: __has_attribute(x) must not be reached when the compiler does not know it (MSVC):
12 // even behind a defined(__has_attribute) &&, it would not parse
13 #if defined(__has_attribute)
14 #define KN_HAS_ATTRIBUTE(x) __has_attribute(x)
15 #else
16 #define KN_HAS_ATTRIBUTE(x) 0
17 #endif
18
19 #if defined(__GNUC__) && (__GNUC__ >= 4)
20 #define KN_GNUC 1
21 #else
22 #define KN_GNUC 0
23 #endif
24
25 // NOTE: On Windows, the DLL exports its API (KRONKNET_BUILD_DLL, set when it is built),
26 // and who links with it can import it (KRONKNET_USE_DLL, set by the kronknet-shared target).
27 // Without either, nothing is needed: a static library needs none, and the API is only
28 // functions, which a DLL gives through its import library anyway
29 #if defined(_WIN32) || defined(__CYGWIN__)
30 #if defined(KRONKNET_BUILD_DLL)
31 #define KN_API __declspec(dllexport)
32 #elif defined(KRONKNET_USE_DLL)
33 #define KN_API __declspec(dllimport)
34 #else
35 #define KN_API
36 #endif
37 #elif KN_GNUC || KN_HAS_ATTRIBUTE(visibility)
38 #define KN_API __attribute__((visibility("default")))
39 #else
40 #define KN_API
41 #endif
42
43 #if KN_GNUC || KN_HAS_ATTRIBUTE(unused)
44 #define KN_UNUSED __attribute__((unused))
45 #else
46 #define KN_UNUSED
47 #endif
48
49 #if KN_GNUC || KN_HAS_ATTRIBUTE(hot)
50 #define KN_HOT __attribute__((hot))
51 #else
52 #define KN_HOT
53 #endif
54
55 #if KN_GNUC || KN_HAS_ATTRIBUTE(cold)
56 #define KN_COLD __attribute__((cold))
57 #else
58 #define KN_COLD
59 #endif
60
61#endif /* KRONKNET_MACROS_OPTIMIZATION_H */