src/ucx/cx/common.h

changeset 621
956c03c25edd
parent 582
82b60a8dd55c
child 645
0c85c4cd0dd8
equal deleted inserted replaced
620:a202cb1ee175 621:956c03c25edd
47 * <a href="https://sourceforge.net/p/ucx/code">https://sourceforge.net/p/ucx/code</a> 47 * <a href="https://sourceforge.net/p/ucx/code">https://sourceforge.net/p/ucx/code</a>
48 * -&nbsp;or&nbsp;- 48 * -&nbsp;or&nbsp;-
49 * <a href="https://uap-core.de/hg/ucx">https://uap-core.de/hg/ucx</a> 49 * <a href="https://uap-core.de/hg/ucx">https://uap-core.de/hg/ucx</a>
50 * </p> 50 * </p>
51 * 51 *
52 * <h2>LICENCE</h2> 52 * <h2>LICENSE</h2>
53 * 53 *
54 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. 54 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
55 * 55 *
56 * Redistribution and use in source and binary forms, with or without 56 * Redistribution and use in source and binary forms, with or without
57 * modification, are permitted provided that the following conditions are met: 57 * modification, are permitted provided that the following conditions are met:
129 */ 129 */
130 #define __attribute__(x) 130 #define __attribute__(x)
131 #endif 131 #endif
132 132
133 /** 133 /**
134 * Inform the compiler that falling through a switch case is intentional.
135 */
136 #define cx_attr_fallthrough __attribute__((__fallthrough__))
137
138 /**
134 * All pointer arguments must be non-NULL. 139 * All pointer arguments must be non-NULL.
135 */ 140 */
136 #define cx_attr_nonnull __attribute__((__nonnull__)) 141 #define cx_attr_nonnull __attribute__((__nonnull__))
137 142
138 /** 143 /**
182 /** 187 /**
183 * No support for @c null_terminated_string_arg in clang or GCC below 14. 188 * No support for @c null_terminated_string_arg in clang or GCC below 14.
184 */ 189 */
185 #define cx_attr_cstr_arg(idx) 190 #define cx_attr_cstr_arg(idx)
186 /** 191 /**
187 * No support for access attribute in clang. 192 * No support for the access attribute in clang.
188 */ 193 */
189 #define cx_attr_access(mode, ...) 194 #define cx_attr_access(mode, ...)
190 #else 195 #else
191 #if __GNUC__ < 10 196 #if __GNUC__ < 10
192 /** 197 /**
258 #ifdef _MSC_VER 263 #ifdef _MSC_VER
259 // fix missing _Thread_local support 264 // fix missing _Thread_local support
260 #define _Thread_local __declspec(thread) 265 #define _Thread_local __declspec(thread)
261 #endif // _MSC_VER 266 #endif // _MSC_VER
262 267
268 // ---------------------------------------------------------------------------
269 // Exported and inlined functions
270 // ---------------------------------------------------------------------------
271
263 #if defined(CX_WINDLL_EXPORT) 272 #if defined(CX_WINDLL_EXPORT)
264 #define cx_attr_export __declspec(dllexport) 273 #define CX_EXPORT __declspec(dllexport)
265 #elif defined(CX_WINDLL) 274 #elif defined(CX_WINDLL)
266 #define cx_attr_export __declspec(dllimport) 275 #define CX_EXPORT __declspec(dllimport)
267 #else 276 #else
268 /** Only used for building Windows DLLs. */ 277 /** Only used for building Windows DLLs. */
269 #define cx_attr_export 278 #define CX_EXPORT
270 #endif // CX_WINDLL / CX_WINDLL_EXPORT 279 #endif // CX_WINDLL / CX_WINDLL_EXPORT
271 280
281 #ifdef __GNUC__
282 /**
283 * Declares a function to be inlined.
284 */
285 #define CX_INLINE __attribute__((always_inline)) static inline
286 #else
287 #define CX_INLINE static inline
288 #endif
289 /**
290 * Declares a compatibility function for C++ builds.
291 */
292 #define CX_CPPDECL static inline
293
272 // --------------------------------------------------------------------------- 294 // ---------------------------------------------------------------------------
273 // Useful function pointers 295 // Useful function pointers
274 // --------------------------------------------------------------------------- 296 // ---------------------------------------------------------------------------
275 297
276 /** 298 /**
277 * Function pointer compatible with fwrite-like functions. 299 * Function pointer compatible with fwrite-like functions.
278 */ 300 */
279 typedef size_t (*cx_write_func)( 301 typedef size_t (*cx_write_func)(const void*, size_t, size_t, void*);
280 const void *,
281 size_t,
282 size_t,
283 void *
284 );
285 302
286 /** 303 /**
287 * Function pointer compatible with fread-like functions. 304 * Function pointer compatible with fread-like functions.
288 */ 305 */
289 typedef size_t (*cx_read_func)( 306 typedef size_t (*cx_read_func)(void*, size_t, size_t, void*);
290 void *,
291 size_t,
292 size_t,
293 void *
294 );
295 307
296 // --------------------------------------------------------------------------- 308 // ---------------------------------------------------------------------------
297 // Utility macros 309 // Utility macros
298 // --------------------------------------------------------------------------- 310 // ---------------------------------------------------------------------------
299 311
341 * @retval non-zero the multiplication would overflow 353 * @retval non-zero the multiplication would overflow
342 */ 354 */
343 #if __cplusplus 355 #if __cplusplus
344 extern "C" 356 extern "C"
345 #endif 357 #endif
346 cx_attr_export int cx_szmul_impl(size_t a, size_t b, size_t *result); 358 CX_EXPORT int cx_szmul_impl(size_t a, size_t b, size_t *result);
347 #endif // cx_szmul 359 #endif // cx_szmul
348 360
349
350
351 #endif // UCX_COMMON_H 361 #endif // UCX_COMMON_H

mercurial