Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Revert "Make gras compil with Visual C++." This commit is too large/unreadable. It...
[simgrid.git] / include / xbt / misc.h
1 /* xbt.h - Public interface to the xbt (gras's toolbox)                     */
2
3 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
4  * All rights reserved.                                                     */
5
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. */
8
9 #ifndef XBT_MISC_H
10 #define XBT_MISC_H
11
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
25
26 #else /* !__GNUC__ */
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
35
36 #endif /* !__GNUC__ */
37
38 /* inline and __FUNCTION__ are only in GCC when -ansi is off */
39
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_FUNC__ __func__   /* ISO-C99 compliant */
44 #else
45 # define _XBT_FUNCTION "function"
46 #endif
47
48 #ifndef __cplusplus
49 #    if defined(__GNUC__) && ! defined(__STRICT_ANSI__)
50 #        define XBT_INLINE inline
51 #    elif (defined(__STDC__) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
52 #        define XBT_INLINE inline
53 #    elif defined(__BORLANDC__) && !defined(__STRICT_ANSI__)
54 #        define XBT_INLINE __inline
55 #    else
56 #        define XBT_INLINE
57 #    endif
58 # else
59 #    define XBT_INLINE  inline
60 #endif
61
62 /* improvable on gcc (by evaluating arguments only once), but wouldn't be portable */
63 #ifdef MIN
64 # undef MIN
65 #endif
66 #define MIN(a,b) ((a)<(b)?(a):(b))
67
68 #ifdef MAX
69 # undef MAX
70 #endif
71 #define MAX(a,b) ((a)>(b)?(a):(b))
72
73
74 /* 
75  * Function calling convention (not used for now) 
76  */
77
78 #ifdef _WIN32
79 #  ifndef _XBT_CALL
80 #    define _XBT_CALL __cdecl
81 #   endif
82 #else
83 #  define _XBT_CALL
84 #endif
85
86 /* Handle import/export stuff
87  * 
88  * Rational of XBT_PUBLIC: 
89  *   * This is for library symbols visible from the application-land.
90  *     Basically, any symbols defined in the include/directory must be 
91  *     like this (plus some other globals). 
92  *
93  *     UNIX coders should just think of it as a special way to say "extern".
94  *
95  *   * If you build the DLL, define the DLL_EXPORT symbol so that all symbols
96  *     actually get exported by this file.
97
98  *   * If you do a static windows compilation, define DLL_STATIC, both when
99  *     compiling the application files and when compiling the library.
100  *
101  *   * If you link your application against the DLL or if you do a UNIX build,
102  *     don't do anything special. This file will do the right thing for you 
103  *     by default.
104  *
105  * 
106  * Rational of XBT_EXPORT_NO_IMPORT: (windows-only cruft)
107  *   * Symbols which must be exported in the DLL, but not imported from it.
108  * 
109  *   * This is obviously useful for initialized globals (which cannot be 
110  *     extern or similar).
111  *   * This is also used in the log mecanism where a macro creates the 
112  *     variable automatically. When the macro is called from within SimGrid,
113  *     the symbol must be exported, but when called  from within the client
114  *     code, it must not try to retrieve the symbol from the DLL since it's
115  *      not in there.
116  * 
117  * Rational of XBT_IMPORT_NO_EXPORT: (windows-only cruft)
118  *   * Symbols which must be imported from the DLL, but not explicitely 
119  *     exported from it.
120  * 
121  *   * The root log category is already exported, but not imported explicitely 
122  *     when creating a subcategory since we cannot import the parent category 
123  *     to deal with the fact that the parent may be in application space, not 
124  *     DLL space.
125  */
126
127
128 /* Build the DLL */
129 #if defined(DLL_EXPORT)
130 #  define XBT_PUBLIC(type)            __declspec(dllexport) type
131 #  define XBT_EXPORT_NO_IMPORT(type)  __declspec(dllexport) type
132 #  define XBT_IMPORT_NO_EXPORT(type)  type
133 #  define XBT_PUBLIC_DATA(type)       __declspec(dllexport) type
134
135 /* Pack everything up statically */
136 #elif defined(DLL_STATIC)
137 #  define XBT_PUBLIC(type)           extern type
138 #  define XBT_EXPORT_NO_IMPORT(type)  type
139 #  define XBT_IMPORT_NO_EXPORT(type)  type
140 #  define XBT_PUBLIC_DATA(type)       extern type
141
142
143 /* Link against the DLL */
144 #elif (defined(_WIN32) && !defined(DLL_EXPORT) && !defined(DLL_STATIC))
145 #  define XBT_PUBLIC(type)              __declspec(dllimport) type
146 #  define XBT_EXPORT_NO_IMPORT(type)    type
147 #  define XBT_IMPORT_NO_EXPORT(type)    __declspec(dllimport) type
148 #  define XBT_PUBLIC_DATA(type)         __declspec(dllimport) type
149
150 /* UNIX build */
151 #else
152 #  define XBT_PUBLIC(type)            extern type
153 #  define XBT_EXPORT_NO_IMPORT(type)  type
154 #  define XBT_IMPORT_NO_EXPORT(type)  type
155 #  define XBT_PUBLIC_DATA(type)       extern type
156 #endif
157
158 #if !defined (max) && !defined(__cplusplus)
159 #  define max(a,b)      (((a) > (b)) ? (a) : (b))
160 #endif
161 #if !defined (min) && !defined(__cplusplus)
162 #  define min(a,b)      (((a) < (b)) ? (a) : (b))
163 #endif
164
165 #define TRUE  1
166 #define FALSE 0
167
168 #define XBT_MAX_CHANNEL 10      /* FIXME: killme */
169 /*! C++ users need love */
170 #ifndef SG_BEGIN_DECL
171 # ifdef __cplusplus
172 #  define SG_BEGIN_DECL() extern "C" {
173 # else
174 #  define SG_BEGIN_DECL()
175 # endif
176 #endif
177
178 #ifndef SG_END_DECL
179 # ifdef __cplusplus
180 #  define SG_END_DECL() }
181 # else
182 #  define SG_END_DECL()
183 # endif
184 #endif
185 /* End of cruft for C++ */
186
187 SG_BEGIN_DECL()
188
189 XBT_PUBLIC(const char *) xbt_procname(void);
190
191 #define XBT_BACKTRACE_SIZE 10   /* FIXME: better place? Do document */
192
193 SG_END_DECL()
194 #endif /* XBT_MISC_H */