1 /* xbt.h - Public interface to the xbt (gras's toolbox) */
3 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
12 /* Attributes are only in recent versions of GCC */
13 #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4))
14 # define _XBT_GNUC_PRINTF( format_idx, arg_idx ) \
15 __attribute__((__format__ (__printf__, format_idx, arg_idx)))
16 # define _XBT_GNUC_SCANF( format_idx, arg_idx ) \
17 __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
18 # define _XBT_GNUC_FORMAT( arg_idx ) \
19 __attribute__((__format_arg__ (arg_idx)))
20 # define _XBT_GNUC_NORETURN __attribute__((__noreturn__))
21 # define _XBT_GNUC_UNUSED __attribute__((__unused__))
22 # define _XBT_GNUC_CONSTRUCTOR __attribute__((__constructor__))
23 # define _XBT_GNUC_DESTRUCTOR __attribute__((__destructor__))
24 # undef _XBT_NEED_INIT_PRAGMA
27 # define _XBT_GNUC_PRINTF( format_idx, arg_idx )
28 # define _XBT_GNUC_SCANF( format_idx, arg_idx )
29 # define _XBT_GNUC_FORMAT( arg_idx )
30 # define _XBT_GNUC_NORETURN
31 # define _XBT_GNUC_UNUSED
32 # define _XBT_GNUC_CONSTRUCTOR
33 # define _XBT_GNUC_DESTRUCTOR
34 # define _XBT_NEED_INIT_PRAGMA 1
36 #endif /* !__GNUC__ */
38 /* inline and __FUNCTION__ are only in GCC when -ansi is off */
40 #if defined(__GNUC__) && ! defined(__STRICT_ANSI__)
41 # define _XBT_FUNCTION __FUNCTION__
42 #elif (defined(__STDC__) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
43 # define _XBT_FUNCTION __func__ /* ISO-C99 compliant */
45 # define _XBT_FUNCTION "function"
52 # if defined(__GNUC__) && ! defined(__STRICT_ANSI__)
53 # define XBT_INLINE inline
54 # elif (defined(__STDC__) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
55 # define XBT_INLINE inline
56 # elif defined(__BORLANDC__) && !defined(__STRICT_ANSI__)
57 # define XBT_INLINE __inline
62 # if defined (__VISUALC__)
63 # define XBT_INLINE __inline
65 # define XBT_INLINE inline
67 # endif /* __cplusplus */
70 /* improvable on gcc (by evaluating arguments only once), but wouldn't be portable */
74 #define MIN(a,b) ((a)<(b)?(a):(b))
79 #define MAX(a,b) ((a)>(b)?(a):(b))
82 * Expands to `one' if there is only one argument for the variadic part.
83 * Otherwise, expands to `more'.
84 * Works with up to 63 arguments, which is the maximum mandated by the C99
87 #define _XBT_IF_ONE_ARG(one, more, ...) \
88 _XBT_IF_ONE_ARG_(__VA_ARGS__, \
89 more, more, more, more, more, more, more, more, \
90 more, more, more, more, more, more, more, more, \
91 more, more, more, more, more, more, more, more, \
92 more, more, more, more, more, more, more, more, \
93 more, more, more, more, more, more, more, more, \
94 more, more, more, more, more, more, more, more, \
95 more, more, more, more, more, more, more, more, \
96 more, more, more, more, more, more, more, one)
97 #define _XBT_IF_ONE_ARG_(a64, a63, a62, a61, a60, a59, a58, a57, \
98 a56, a55, a54, a53, a52, a51, a50, a49, \
99 a48, a47, a46, a45, a44, a43, a42, a41, \
100 a40, a39, a38, a37, a36, a35, a34, a33, \
101 a32, a31, a30, a29, a28, a27, a26, a25, \
102 a24, a23, a22, a21, a20, a19, a18, a17, \
103 a16, a15, a14, a13, a12, a11, a10, a9, \
104 a8, a7, a6, a5, a4, a3, a2, a1, N, ...) N
107 * Function calling convention (not used for now)
112 # define _XBT_CALL __cdecl
118 /* Handle import/export stuff
120 * Rational of XBT_PUBLIC:
121 * * This is for library symbols visible from the application-land.
122 * Basically, any symbols defined in the include/directory must be
123 * like this (plus some other globals).
125 * UNIX coders should just think of it as a special way to say "extern".
127 * * If you build the DLL, define the DLL_EXPORT symbol so that all symbols
128 * actually get exported by this file.
130 * * If you do a static windows compilation, define DLL_STATIC, both when
131 * compiling the application files and when compiling the library.
133 * * If you link your application against the DLL or if you do a UNIX build,
134 * don't do anything special. This file will do the right thing for you
138 * Rational of XBT_EXPORT_NO_IMPORT: (windows-only cruft)
139 * * Symbols which must be exported in the DLL, but not imported from it.
141 * * This is obviously useful for initialized globals (which cannot be
142 * extern or similar).
143 * * This is also used in the log mecanism where a macro creates the
144 * variable automatically. When the macro is called from within SimGrid,
145 * the symbol must be exported, but when called from within the client
146 * code, it must not try to retrieve the symbol from the DLL since it's
149 * Rational of XBT_IMPORT_NO_EXPORT: (windows-only cruft)
150 * * Symbols which must be imported from the DLL, but not explicitely
153 * * The root log category is already exported, but not imported explicitely
154 * when creating a subcategory since we cannot import the parent category
155 * to deal with the fact that the parent may be in application space, not
161 #if defined(DLL_EXPORT)
162 # define XBT_PUBLIC(type) __declspec(dllexport) type
163 # define XBT_EXPORT_NO_IMPORT(type) __declspec(dllexport) type
164 # define XBT_IMPORT_NO_EXPORT(type) type
165 # define XBT_PUBLIC_DATA(type) __declspec(dllexport) type
167 /* Pack everything up statically */
168 #elif defined(DLL_STATIC)
169 # define XBT_PUBLIC(type) extern type
170 # define XBT_EXPORT_NO_IMPORT(type) type
171 # define XBT_IMPORT_NO_EXPORT(type) type
172 # define XBT_PUBLIC_DATA(type) extern type
174 /* Link against the DLL */
175 #elif (defined(_XBT_WIN32) && !defined(DLL_EXPORT) && !defined(DLL_STATIC))
176 # define XBT_PUBLIC(type) __declspec(dllimport) type
177 # define XBT_EXPORT_NO_IMPORT(type) type
178 # define XBT_IMPORT_NO_EXPORT(type) __declspec(dllimport) type
179 # define XBT_PUBLIC_DATA(type) __declspec(dllimport) type
183 # define XBT_PUBLIC(type) extern type
184 # define XBT_EXPORT_NO_IMPORT(type) type
185 # define XBT_IMPORT_NO_EXPORT(type) type
186 # define XBT_PUBLIC_DATA(type) extern type
189 #if !defined (max) && !defined(__cplusplus)
190 # define max(a,b) (((a) > (b)) ? (a) : (b))
192 #if !defined (min) && !defined(__cplusplus)
193 # define min(a,b) (((a) < (b)) ? (a) : (b))
199 #define XBT_MAX_CHANNEL 10 /* FIXME: killme */
200 /*! C++ users need love */
201 #ifndef SG_BEGIN_DECL
203 # define SG_BEGIN_DECL() extern "C" {
205 # define SG_BEGIN_DECL()
211 # define SG_END_DECL() }
213 # define SG_END_DECL()
216 /* End of cruft for C++ */
220 XBT_PUBLIC(const char *) xbt_procname(void);
222 #define XBT_BACKTRACE_SIZE 10 /* FIXME: better place? Do document */
225 #endif /* XBT_MISC_H */