Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
redefinition of the macro XBT_PUBLIC_DATA
[simgrid.git] / include / xbt / misc.h
1 /* $Id$ */
2
3 /* xbt.h - Public interface to the xbt (gras's toolbox)                     */
4
5 /* Copyright (c) 2004 Martin Quinson.                                       */
6 /* Copyright (c) 2004 Arnaud Legrand.                                       */
7 /* All rights reserved.                                                     */
8
9 /* This program is free software; you can redistribute it and/or modify it
10  * under the terms of the license (GNU LGPL) which comes with this package. */
11
12 #ifndef XBT_MISC_H
13 #define XBT_MISC_H
14
15 /* Attributes are only in recent versions of GCC */
16 #if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
17 # define _XBT_GNUC_PRINTF( format_idx, arg_idx )    \
18            __attribute__((__format__ (__printf__, format_idx, arg_idx)))
19 # define _XBT_GNUC_SCANF( format_idx, arg_idx )     \
20                __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
21 # define _XBT_GNUC_FORMAT( arg_idx )                \
22                    __attribute__((__format_arg__ (arg_idx)))
23 # define _XBT_GNUC_NORETURN __attribute__((__noreturn__))
24 # define _XBT_GNUC_UNUSED  __attribute__((unused))
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
33 #endif  /* !__GNUC__ */
34
35 /* inline and __FUNCTION__ are only in GCC when -ansi is off */
36
37 #if defined(__GNUC__) && ! defined(__STRICT_ANSI__)
38 # define _XBT_FUNCTION __FUNCTION__
39 #elif (defined(__STDC__) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
40 # define _XBT_FUNC__ __func__      /* ISO-C99 compliant */
41 #else
42 # define _XBT_FUNCTION "function"
43 #endif
44
45 #ifndef __cplusplus
46 #    if defined(__GNUC__) && ! defined(__STRICT_ANSI__)
47 #        define XBT_INLINE inline
48 #    elif (defined(__STDC__) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
49 #        define XBT_INLINE inline
50 #    elif defined(__BORLANDC__) && !defined(__STRICT_ANSI__)
51 #        define XBT_INLINE __inline
52 #    else
53 #        define XBT_INLINE
54 #    endif
55 # else
56 #    define XBT_INLINE  inline
57 #endif
58
59 /* 
60  * Function calling convention (not used for now) 
61  */
62  
63 #ifdef _WIN32
64 #  ifndef _XBT_CALL
65 #    define _XBT_CALL __cdecl
66 #   endif
67 #else 
68 #  define _XBT_CALL
69 #endif
70
71 /* Handle import/export stuff
72  * 
73  * Rational of XBT_PUBLIC: 
74  *   * This is for library symbols visible from the application-land.
75  *     Basically, any symbols defined in the include/directory must be 
76  *     like this (plus some other globals). 
77  *
78  *     UNIX coders should just think of it as a special way to say "extern".
79  *
80  *   * If you build the DLL, define the DLL_EXPORT symbol so that all symbols
81  *     actually get exported by this file.
82
83  *   * If you do a static windows compilation, define DLL_STATIC, both when
84  *     compiling the application files and when compiling the library.
85  *
86  *   * If you link your application against the DLL or if you do a UNIX build,
87  *     don't do anything special. This file will do the right thing for you 
88  *     by default.
89  *
90  * 
91  * Rational of XBT_EXPORT_NO_IMPORT: (windows-only cruft)
92  *   * Symbols which must be exported in the DLL, but not imported from it.
93  * 
94  *   * This is obviously useful for initialized globals (which cannot be 
95  *     extern or similar).
96  *   * This is also used in the log mecanism where a macro creates the 
97  *     variable automatically. When the macro is called from within SimGrid,
98  *     the symbol must be exported, but when called  from within the client
99  *     code, it must not try to retrieve the symbol from the DLL since it's
100  *      not in there.
101  * 
102  * Rational of XBT_IMPORT_NO_EXPORT: (windows-only cruft)
103  *   * Symbols which must be imported from the DLL, but not explicitely 
104  *     exported from it.
105  * 
106  *   * The root log category is already exported, but not imported explicitely 
107  *     when creating a subcategory since we cannot import the parent category 
108  *     to deal with the fact that the parent may be in application space, not 
109  *     DLL space.
110  */
111
112
113 /* Build the DLL */
114 #if defined(DLL_EXPORT)
115 #  define XBT_PUBLIC(type)            __declspec(dllexport) type
116 #  define XBT_EXPORT_NO_IMPORT(type)  __declspec(dllexport) type
117 #  define XBT_IMPORT_NO_EXPORT(type)  type 
118 #  define XBT_PUBLIC_DATA                        __declspec(dllexport)
119
120 /* Pack everything up statically */
121 #elif defined(DLL_STATIC)
122 #  define XBT_PUBLIC(type)            type
123 #  define XBT_EXPORT_NO_IMPORT(type)  type
124 #  define XBT_IMPORT_NO_EXPORT(type)  type
125 #  define XBT_PUBLIC_DATA                 
126      
127
128 /* Link against the DLL */
129 #elif (defined(_WIN32) && !defined(DLL_EXPORT))
130 #  define XBT_PUBLIC(type)              __declspec(dllimport) type
131 #  define XBT_EXPORT_NO_IMPORT(type)    type
132 #  define XBT_IMPORT_NO_EXPORT(type)    __declspec(dllimport) type
133 #  define XBT_PUBLIC_DATA                               __declspec(dllimport)           
134
135 /* Non-UNIX build. Let's keep sain here ;) */
136 #else
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       
141 #endif
142    
143
144
145
146 #ifndef max
147 #  define max(a,b)      (((a) > (b)) ? (a) : (b))
148 #endif
149 #ifndef min
150 #  define min(a,b)      (((a) < (b)) ? (a) : (b))
151 #endif
152
153 #define TRUE  1
154 #define FALSE 0
155
156 #define XBT_MAX_CHANNEL 10 /* FIXME: killme */
157 /*! C++ users need love */
158 #ifndef SG_BEGIN_DECL
159 # ifdef __cplusplus
160 #  define SG_BEGIN_DECL() extern "C" {
161 # else
162 #  define SG_BEGIN_DECL() 
163 # endif
164 #endif
165
166 /*! C++ users need love */
167 #ifndef SG_END_DECL
168 # ifdef __cplusplus
169 #  define SG_END_DECL() }
170 # else
171 #  define SG_END_DECL() 
172 # endif
173 #endif
174 /* End of cruft for C++ */
175
176 SG_BEGIN_DECL()
177
178 XBT_PUBLIC(const char *)xbt_procname(void);
179
180 #define XBT_BACKTRACE_SIZE 10 /* FIXME: better place? Do document */
181    
182 SG_END_DECL()
183
184 #endif /* XBT_MISC_H */
185
186
187
188