Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
define the XBT_IMPORT_NO_PUBLIC macro for imported but not exported type
[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  *   * If you build the DLL you must pass the right value of XBT_PUBLIC in the project : to do this you must define the DLL_EXPORT macro
75  *   * If you do a static compilation, you must define the macro DLL_STATIC
76  *   * If you link your code against the DLL, this file defines the macro to '__declspec(dllimport)' for you
77  *   * If you compile under unix, this file defines the macro to 'extern', even if it's not mandatory with modern compilers
78  * 
79  * Rational of XBT_PUBLIC_NO_IMPORT:
80  *   * This is for symbols which must be exported in the DLL, but not imported from it. 
81  *     This is obviously useful for initialized globals (which cannot be extern or similar).
82  *     This is also used in the log mecanism where a macro creates the variable automatically.
83  *      When the macro is called from within SimGrid, the symbol must be exported, but when called 
84  *      from within the client code, it must not try to retrieve the symbol from the DLL since it's not in there.
85  */
86
87
88 #ifdef DLL_EXPORT
89 #  define XBT_PUBLIC(type)                        __declspec(dllexport) type
90 #  define XBT_PUBLIC_NO_IMPORT(type)  __declspec(dllexport) type
91 #  define XBT_IMPORT_NO_PUBLIC(type)  type 
92 #else
93 #  ifdef DLL_STATIC
94 #    define XBT_PUBLIC(type)               type
95 #    define XBT_PUBLIC_NO_IMPORT(type) type
96 #   define XBT_IMPORT_NO_PUBLIC(type)  type 
97 #  else
98 #    ifdef _WIN32
99 #      define XBT_PUBLIC(type)               __declspec(dllimport) type
100 #      define XBT_PUBLIC_NO_IMPORT(type) type
101 #      define XBT_IMPORT_NO_PUBLIC(type) __declspec(dllimport) type
102 #        else
103 #      define XBT_PUBLIC(type)               extern type
104 #      define XBT_PUBLIC_NO_IMPORT(type) type
105 #      define XBT_IMPORT_NO_PUBLIC(type) type
106 #    endif
107 #  endif
108 #endif
109    
110
111
112
113 #ifndef max
114 #  define max(a, b) (((a) > (b))?(a):(b))
115 #endif
116 #ifndef min
117 #  define min(a, b) (((a) < (b))?(a):(b))
118 #endif
119
120 #define TRUE  1
121 #define FALSE 0
122
123 #define XBT_MAX_CHANNEL 10 /* FIXME: killme */
124 /*! C++ users need love */
125 #ifndef SG_BEGIN_DECL
126 # ifdef __cplusplus
127 #  define SG_BEGIN_DECL() extern "C" {
128 # else
129 #  define SG_BEGIN_DECL() 
130 # endif
131 #endif
132
133 /*! C++ users need love */
134 #ifndef SG_END_DECL
135 # ifdef __cplusplus
136 #  define SG_END_DECL() }
137 # else
138 #  define SG_END_DECL() 
139 # endif
140 #endif
141 /* End of cruft for C++ */
142
143 SG_BEGIN_DECL()
144
145 XBT_PUBLIC(const char *)xbt_procname(void);
146
147 #define XBT_BACKTRACE_SIZE 10 /* FIXME: better place? Do document */
148    
149 SG_END_DECL()
150
151 #endif /* XBT_MISC_H */
152
153
154
155