Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
text file used in trace usage test case
[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 /* Windows __declspec(). */
60 #if defined(_WIN32) && defined(__BORLANDC__)
61 #  if(__BORLANDC__ < 0x540)
62 #    if (defined (__DLL) || defined (_DLL) || defined (_WINDLL) || defined (_RTLDLL) || defined (_XBT_USE_DYNAMIC_LIB) ) && ! defined (_XBT_USE_STAT
63 #      undef  _XBT_USE_DECLSPEC
64 #      define _XBT_USE_DECLSPEC
65 #    endif
66 #  else
67 #  if ( defined (__DLL) || defined (_DLL) || defined (_WINDLL) || defined (_RTLDLL) || defined(_AFXDLL) || defined (_XBT_USE_DYNAMIC_LIB) )
68 #    undef  _XBT_USE_DECLSPEC
69 #    define _XBT_USE_DECLSPEC 1
70 #  endif
71 #  endif
72 #endif
73
74 #if defined (_XBT_USE_DECLSPEC) /* using export/import technique */
75
76 #    ifndef _XBT_EXPORT_DECLSPEC
77 #        define _XBT_EXPORT_DECLSPEC
78 #    endif
79
80 #    ifndef _XBT_IMPORT_DECLSPEC
81 #        define _XBT_IMPORT_DECLSPEC
82 #    endif
83
84 #    if defined (_XBT_DESIGNATED_DLL) /* this is a lib which will contain xbt exports */
85 #        define  XBT_PUBLIC        _XBT_EXPORT_DECLSPEC
86 #    else
87 #        define  XBT_PUBLIC        _XBT_IMPORT_DECLSPEC   /* other modules, importing xbt exports */
88 #    endif
89
90 #else /* not using DLL export/import specifications */
91
92 #    define XBT_PUBLIC
93
94 #endif /* #if defined (_XBT_USE_DECLSPEC) */
95
96 /* Function calling convention (not used for now) */
97 #if !defined (_XBT_CALL)
98 #define _XBT_CALL
99 #endif
100
101
102
103 #ifndef max
104 #  define max(a, b) (((a) > (b))?(a):(b))
105 #endif
106 #ifndef min
107 #  define min(a, b) (((a) < (b))?(a):(b))
108 #endif
109
110 #define TRUE  1
111 #define FALSE 0
112
113 #define XBT_MAX_CHANNEL 10 /* FIXME: killme */
114 /*! C++ users need love */
115 #ifndef SG_BEGIN_DECL
116 # ifdef __cplusplus
117 #  define SG_BEGIN_DECL() extern "C" {
118 # else
119 #  define SG_BEGIN_DECL() 
120 # endif
121 #endif
122
123 /*! C++ users need love */
124 #ifndef SG_END_DECL
125 # ifdef __cplusplus
126 #  define SG_END_DECL() }
127 # else
128 #  define SG_END_DECL() 
129 # endif
130 #endif
131 /* End of cruft for C++ */
132
133 SG_BEGIN_DECL()
134
135 XBT_PUBLIC const char *xbt_procname(void);
136
137 #define XBT_BACKTRACE_SIZE 10 /* FIXME: better place? Do document */
138    
139 SG_END_DECL()
140
141 #endif /* XBT_MISC_H */