KallistiOS  ##version##
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
cdefs.h
Go to the documentation of this file.
1 /* KallistiOS ##version##
2 
3  kos/cdefs.h
4  Copyright (C)2002,2004 Dan Potter
5 
6  Based loosely around some stuff in BSD's sys/cdefs.h
7 */
8 
9 /** \file kos/cdefs.h
10  \brief Potentially useful definitions for C Programs.
11 
12  This file contains definitions of various __attribute__ directives in
13  shorter forms for use in programs (to aid in optimization, mainly).
14 
15  \author Dan Potter
16 */
17 
18 #ifndef __KOS_CDEFS_H
19 #define __KOS_CDEFS_H
20 
21 #include <sys/cdefs.h>
22 
23 /* Check GCC version */
24 #ifndef _arch_ps2
25 # if __GNUC__ < 2
26 # warning Your GCC is too old. This will probably not work right.
27 # endif
28 
29 # if __GNUC__ == 2 && __GNUC_MINOR__ < 97
30 # warning Your GCC is too old. This will probably not work right.
31 # endif
32 #endif /* _arch_ps2 */
33 
34 /* Special function/variable attributes */
35 
36 /** \brief Identify a function that will never return. */
37 #define __noreturn __attribute__((__noreturn__))
38 
39 /** \brief Identify a function that has no side effects other than its return,
40  and only uses its arguments for any work. */
41 #define __pure __attribute__((__const__))
42 
43 /** \brief Identify a function or variable that may be unused. */
44 #define __unused __attribute__((__unused__))
45 
46 /** \brief Alias for \ref __noreturn. For BSD compatibility. */
47 #define __dead2 __noreturn /* BSD compat */
48 
49 /** \brief Alias for \ref __pure. Fore BSD compatibility. */
50 #define __pure2 __pure /* ditto */
51 
52 /* Printf/Scanf-like declaration */
53 /** \brief Identify a function as accepting formatting like printf().
54 
55  Using this macro allows GCC to typecheck calls to printf-like functions,
56  which can aid in finding mistakes.
57 
58  \param fmtarg The argument number (1-based) of the format string.
59  \param firstvararg The argument number of the first vararg (the ...).
60 */
61 #define __printflike(fmtarg, firstvararg) \
62  __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
63 
64 /** \brief Identify a function as accepting formatting like scanf().
65 
66  Using this macro allows GCC to typecheck calls to scanf-like functions,
67  which can aid in finding mistakes.
68 
69  \param fmtarg The argument number (1-based) of the format string.
70  \param firstvararg The argument number of the first vararg (the ...).
71 */
72 #define __scanflike(fmtarg, firstvararg) \
73  __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
74 
75 /* GCC macros for special cases */
76 /* #if __GNUC__ == */
77 
78 #endif /* __KOS_CDEFS_H */
79 
80