plibsys  0.0.4
pmacros.h
Go to the documentation of this file.
1 /*
2  * The MIT License
3  *
4  * Copyright (C) 2010-2017 Alexander Saprykin <saprykin.spb@gmail.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * 'Software'), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
39 #if !defined (PLIBSYS_H_INSIDE) && !defined (PLIBSYS_COMPILATION)
40 # error "Header files shouldn't be included directly, consider using <plibsys.h> instead."
41 #endif
42 
43 #ifndef PLIBSYS_HEADER_PMACROS_H
44 #define PLIBSYS_HEADER_PMACROS_H
45 
46 #include <pmacroscompiler.h>
47 #include <pmacroscpu.h>
48 #include <pmacrosos.h>
49 
50 #include <stdio.h>
51 
52 /* For Clang */
53 #ifndef __has_attribute
54 # define __has_attribute(x) 0
55 #endif
56 
57 #ifndef __has_builtin
58 # define __has_builtin(x) 0
59 #endif
60 
68 #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) || \
69  __has_attribute(warn_unused_result)
70 # define P_GNUC_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
71 #else
72 # define P_GNUC_WARN_UNUSED_RESULT
73 #endif
74 
101 /*
102  * Oracle Solaris Studio since version 12 has visibility attribute for C
103  * compiler, and since version 12.2 for C++ compiler, or since version 8.0
104  * specific __global attribute which is the same.
105  * IBM XL C has support for visibility attributes since version 13.1.
106  * HP C/aC++ has support for visibility attributes since version A.06.15.
107  */
108 
109 #if defined(P_CC_MSVC) || defined(P_CC_BORLAND) || defined(P_CC_WATCOM) || \
110  defined(P_OS_OS2) || (defined(P_OS_BEOS) && !defined(P_CC_GNU)) || \
111  (defined(P_OS_WIN) && defined(P_CC_PGI)) || \
112  ((defined(P_OS_WIN) || defined(P_OS_CYGWIN) || defined(P_OS_MSYS)) && defined(P_CC_GNU))
113 # define P_LIB_GLOBAL_API __declspec(dllexport)
114 # define P_LIB_INTERNAL_API
115 #elif ((__GNUC__ >= 4) && !defined(P_OS_SOLARIS) && !defined(P_OS_HPUX) && !defined(P_OS_AIX)) || \
116  (defined(P_CC_SUN) && __SUNPRO_C >= 0x590) || \
117  (defined(P_CC_SUN) && __SUNPRO_CC >= 0x5110) || \
118  (defined(P_CC_XLC) && __xlC__ >= 0x0D01) || \
119  (defined(P_CC_HP) && __HP_aCC >= 0x061500) || \
120  (defined(P_CC_HP) && __HP_cc >= 0x061500) || \
121  __has_attribute(visibility)
122 # define P_LIB_GLOBAL_API __attribute__ ((visibility ("default")))
123 # define P_LIB_INTERNAL_API __attribute__ ((visibility ("hidden")))
124 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
125 # define P_LIB_GLOBAL_API __global
126 # define P_LIB_INTERNAL_API __hidden
127 #else
128 # define P_LIB_GLOBAL_API
129 # define P_LIB_INTERNAL_API
130 #endif
131 
138 #define P_LIB_API P_LIB_GLOBAL_API
139 
140 /* Oracle Solaris Studio at least since 12.2 has ((noreturn)) attribute */
141 
149 #if defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
150 # define P_NO_RETURN _Noreturn
151 #elif defined(P_CC_MSVC) || (defined(P_CC_BORLAND) && __BORLANDC__ >= 0x0550)
152 # define P_NO_RETURN __declspec(noreturn)
153 #elif __has_attribute(noreturn) || \
154  defined(P_CC_GNU) || \
155  (defined(P_CC_SUN) && __SUNPRO_C >= 0x5110) || \
156  (defined(P_CC_SUN) && __SUNPRO_CC >= 0x5110)
157 # define P_NO_RETURN __attribute__((noreturn))
158 #else
159 # define P_NO_RETURN
160 #endif
161 
176 #if (defined(P_CC_GNU) && (__GNUC__ > 2 && __GNUC_MINOR__ > 0)) || \
177  (defined(P_CC_INTEL) && __INTEL_COMPILER >= 800) || \
178  (defined(P_CC_XLC) && __xlC__ >= 0x0900) || \
179  __has_builtin(__builtin_expect)
180 # define P_LIKELY(x) __builtin_expect(!!(x), 1)
181 # define P_UNLIKELY(x) __builtin_expect(!!(x), 0)
182 #else
183 # define P_LIKELY(x) (x)
184 # define P_UNLIKELY(x) (x)
185 #endif
186 
192 #define P_UNUSED(a) ((void) a)
193 
200 #define P_WARNING(msg) printf ("** Warning: %s **\n", msg)
201 
208 #define P_ERROR(msg) printf ("** Error: %s **\n", msg)
209 
216 #define P_DEBUG(msg) printf ("** Debug: %s **\n", msg)
217 
218 #ifdef DOXYGEN
219 # define PLIBSYS_VERSION_MAJOR
220 # define PLIBSYS_VERSION_MINOR
221 # define PLIBSYS_VERSION_PATCH
222 # define PLIBSYS_VERSION_STR
223 # define PLIBSYS_VERSION
224 #endif
225 
279 #define PLIBSYS_VERSION_CHECK(major, minor, patch) ((major << 16) | (minor << 8) | (patch))
280 
294 #ifdef __cplusplus
295 # define P_BEGIN_DECLS extern "C" {
296 # define P_END_DECLS }
297 #else
298 # define P_BEGIN_DECLS
299 # define P_END_DECLS
300 #endif
301 
302 #endif /* PLIBSYS_HEADER_PMACROS_H */
CPU detection macros.
OS detection macros.
Compiler detection macros.