BRL-CAD
defines.h
Go to the documentation of this file.
1/* D E F I N E S . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2004-2022 United States Government as represented by
5 * the U.S. Army Research Laboratory.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; see the file named COPYING for more
18 * information.
19 */
20
21/** @addtogroup bu_defines
22 *
23 * @brief
24 * These are definitions specific to libbu, used throughout the library.
25 *
26 */
27/** @{ */
28/** @file bu/defines.h */
29
30#ifndef BU_DEFINES_H
31#define BU_DEFINES_H
32
33#include "common.h"
34#include <stddef.h>
35#include <sys/types.h>
36
37#ifndef BU_EXPORT
38# if defined(BU_DLL_EXPORTS) && defined(BU_DLL_IMPORTS)
39# error "Only BU_DLL_EXPORTS or BU_DLL_IMPORTS can be defined, not both."
40# elif defined(BU_DLL_EXPORTS)
41# define BU_EXPORT COMPILER_DLLEXPORT
42# elif defined(BU_DLL_IMPORTS)
43# define BU_EXPORT COMPILER_DLLIMPORT
44# else
45# define BU_EXPORT
46# endif
47#endif
48
49/** All okay return code, not a maskable result. Callers should not rely on
50 * the numerical value. */
51#define BRLCAD_OK 0x0000
52
53/**
54 * Possible maskable return codes from BRL-CAD functions. Callers should not
55 * rely on the actual values or exact numerical equalities but should instead
56 * test via masking.
57 */
58#define BRLCAD_ERROR 0x0001 /**< something went wrong, the action was not performed */
59#define BRLCAD_HELP 0x0002 /**< invalid specification, result contains usage */
60#define BRLCAD_MORE 0x0004 /**< incomplete specification, can specify again interactively */
61#define BRLCAD_QUIET 0x0008 /**< don't set or modify the result string */
62#define BRLCAD_UNKNOWN 0x0010 /**< argv[0] was not a known command */
63#define BRLCAD_EXIT 0x0020 /**< command is requesting a clean application shutdown */
64
65/**
66 * @def BU_DIR_SEPARATOR
67 * the default directory separator character
68 */
69#ifdef DIR_SEPARATOR
70# define BU_DIR_SEPARATOR DIR_SEPARATOR
71#else
72# ifdef DIR_SEPARATOR_2
73# define BU_DIR_SEPARATOR DIR_SEPARATOR_2
74# else
75# ifdef _WIN32
76# define BU_DIR_SEPARATOR '\\'
77# else
78# define BU_DIR_SEPARATOR '/'
79# endif /* _WIN32 */
80# endif /* DIR_SEPARATOR_2 */
81#endif /* DIR_SEPARATOR */
82
83/**
84 * set to the path list separator character
85 */
86#if defined(PATH_SEPARATOR)
87# define BU_PATH_SEPARATOR PATH_SEPARATOR
88#else
89# if defined(_WIN32)
90# define BU_PATH_SEPARATOR ';'
91# else
92# define BU_PATH_SEPARATOR ':'
93# endif /* _WIN32 */
94#endif /* PATH_SEPARATOR */
95
96
97/**
98 * shorthand declaration of a printf-style functions
99 */
100#ifdef HAVE_PRINTF12_ATTRIBUTE
101# define _BU_ATTR_PRINTF12 __attribute__((__format__ (__printf__, 1, 2)))
102#elif !defined(_BU_ATTR_PRINTF12)
103# define _BU_ATTR_PRINTF12
104#endif
105#ifdef HAVE_PRINTF23_ATTRIBUTE
106# define _BU_ATTR_PRINTF23 __attribute__((__format__ (__printf__, 2, 3)))
107#elif !defined(_BU_ATTR_PRINTF23)
108# define _BU_ATTR_PRINTF23
109#endif
110#ifdef HAVE_SCANF23_ATTRIBUTE
111# define _BU_ATTR_SCANF23 __attribute__((__format__ (__scanf__, 2, 3)))
112#elif !defined(_BU_ATTR_SCANF23)
113# define _BU_ATTR_SCANF23
114#endif
115
116/**
117 * shorthand declaration of a function that doesn't return
118 */
119#ifdef HAVE_NORETURN_ATTRIBUTE
120# define _BU_ATTR_NORETURN __attribute__((__noreturn__))
121#else
122# define _BU_ATTR_NORETURN
123#endif
124
125/* For the moment, we need to specially flag some functions
126 * for clang. It's not clear if we will always need to do
127 * this, but for now this suppresses a lot of noise in the
128 * reports */
129#ifdef HAVE_ANALYZER_NORETURN_ATTRIBUTE
130# define _BU_ATTR_ANALYZE_NORETURN __attribute__((analyzer_noreturn))
131#else
132# define _BU_ATTR_ANALYZE_NORETURN
133#endif
134
135/**
136 * shorthand declaration of a function that should always be inline
137 */
138
139#ifdef HAVE_ALWAYS_INLINE_ATTRIBUTE
140# define _BU_ATTR_ALWAYS_INLINE __attribute__((always_inline))
141#else
142# define _BU_ATTR_ALWAYS_INLINE
143#endif
144
145/**
146 * shorthand declaration of a function that will return the exact same
147 * value for the exact same arguments. this implies it's a function
148 * that doesn't examine into any pointer values, doesn't call any
149 * non-cost functions, doesn't read globals, and has no effects except
150 * the return value.
151 */
152#ifdef HAVE_CONST_ATTRIBUTE
153# define _BU_ATTR_CONST __attribute__((const))
154#else
155# define _BU_ATTR_CONST
156#endif
157
158/**
159 * shorthand declaration of a function that depends only on its
160 * parameters and/or global variables. this implies it's a function
161 * that has no effects except the return value and, as such, can be
162 * subject to common subexpression elimination and loop optimization
163 * just as an arithmetic operator would be.
164 */
165#ifdef HAVE_PURE_ATTRIBUTE
166# define _BU_ATTR_PURE __attribute__((pure))
167#else
168# define _BU_ATTR_PURE
169#endif
170
171/**
172 * shorthand declaration of a function that is not likely to be
173 * called. this is typically for debug logging and error routines.
174 */
175#ifdef HAVE_COLD_ATTRIBUTE
176# define _BU_ATTR_COLD __attribute__((cold))
177#else
178# define _BU_ATTR_COLD
179#endif
180
181/**
182 * shorthand declaration of a function that doesn't accept NULL
183 * pointer arguments. if a null pointer is detected during
184 * compilation, a warning/error can be emitted.
185 */
186#ifdef HAVE_NONNULL_ATTRIBUTE
187# define _BU_ATTR_NONNULL __attribute__((nonnull))
188#else
189# define _BU_ATTR_NONNULL
190#endif
191
192/**
193 * shorthand declaration of a function whose return value should not
194 * be ignored. a warning / error will be emitted if the caller does
195 * not use the return value.
196 */
197#ifdef HAVE_WARN_UNUSED_RESULT_ATTRIBUTE
198# define _BU_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
199#else
200# define _BU_ATTR_WARN_UNUSED_RESULT
201#endif
202
203
204/**
205 * shorthand placed before a function _definition_ indicating to some
206 * compilers that it should inline most of the function calls within
207 * the function. this should be used sparingly on functions that are
208 * demonstrably hot, as indicated by a profiler.
209 */
210#ifdef HAVE_FLATTEN_ATTRIBUTE
211# define _BU_ATTR_FLATTEN __attribute__((flatten))
212#else
213# define _BU_ATTR_FLATTEN
214#endif
215
216/**
217 * This macro is used to take the 'C' function name, and convert it at
218 * compile time to the FORTRAN calling convention.
219 *
220 * Lower case, with a trailing underscore.
221 */
222#define BU_FORTRAN(lc, uc) lc ## _
223
224
225/** @} */
226
227#endif /* BU_DEFINES_H */
228
229/*
230 * Local Variables:
231 * mode: C
232 * tab-width: 8
233 * indent-tabs-mode: t
234 * c-file-style: "stroustrup"
235 * End:
236 * ex: shiftwidth=4 tabstop=8
237 */
Header file for the BRL-CAD common definitions.