Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
03257f5f88d0a6061fef2a5600c41c67a5dd1dd9
[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
25 #else   /* !__GNUC__ */
26 # define _XBT_GNUC_PRINTF( format_idx, arg_idx )
27 # define _XBT_GNUC_SCANF( format_idx, arg_idx )
28 # define _XBT_GNUC_FORMAT( arg_idx )
29 # define _XBT_GNUC_NORETURN
30
31 #endif  /* !__GNUC__ */
32
33 /* inline and __FUNCTION__ are only in GCC when -ansi is off */
34
35 #if defined(__GNUC__) && ! defined(__STRICT_ANSI__)
36 # define _XBT_FUNCTION __FUNCTION__
37 # define _XBT_INLINE inline
38 #elif (defined(__STDC__) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
39 # define _XBT_FUNC__ __func__      /* ISO-C99 compliant */
40 # define _XBT_INLINE inline
41 #else
42 # define _XBT_FUNCTION "function"
43 # define _XBT_INLINE 
44 #endif
45
46
47
48 #ifndef max
49 #  define max(a, b) (((a) > (b))?(a):(b))
50 #endif
51 #ifndef min
52 #  define min(a, b) (((a) < (b))?(a):(b))
53 #endif
54
55 #define TRUE  1
56 #define FALSE 0
57
58 #define XBT_MAX_CHANNEL 10 /* FIXME: killme */
59 /*! C++ users need love */
60 #ifndef SG_BEGIN_DECL
61 # ifdef __cplusplus
62 #  define SG_BEGIN_DECL() extern "C" {
63 # else
64 #  define SG_BEGIN_DECL() 
65 # endif
66 #endif
67
68 /*! C++ users need love */
69 #ifndef SG_END_DECL
70 # ifdef __cplusplus
71 #  define SG_END_DECL() }
72 # else
73 #  define SG_END_DECL() 
74 # endif
75 #endif
76 /* End of cruft for C++ */
77
78 SG_BEGIN_DECL()
79 /* Dunno where to place this: needed by config and amok */
80 typedef struct {  
81    char *name;
82    int port;
83 } xbt_host_t;
84
85 const char *xbt_procname(void);
86
87
88 /* Generic function type */
89
90    typedef void (void_f_ppvoid_t)(void**);
91    typedef void (void_f_pvoid_t) (void*);
92
93    typedef int  (int_f_pvoid_pvoid_t) (void*,void*);
94    
95    typedef int  (*int_f_void_t)   (void); /* FIXME: rename it to int_pf_void_t */
96
97 #define XBT_BACKTRACE_SIZE 10 /* FIXME: better place? Do document */
98    
99 SG_END_DECL()
100
101 #endif /* XBT_MISC_H */