637f4c4df96f8de0531dec97049fc4f0731653de
[pspp-builds.git] / src / libpspp / compiler.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 2006 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18    02110-1301, USA. */
19
20 #ifndef COMPILER_H
21 #define COMPILER_H 1
22
23 /* GNU C allows the programmer to declare that certain functions take
24    printf-like arguments, never return, etc.  Conditionalize these
25    declarations on whether gcc is in use. */
26 #if __GNUC__ > 1
27 #define ATTRIBUTE(X) __attribute__ (X)
28
29 /* Only necessary because of a wart in gnulib's xalloc.h. */
30 #define __attribute__(X) __attribute__ (X)
31 #else
32 #define ATTRIBUTE(X)
33 #endif
34
35 /* Marks a function argument as possibly not used. */
36 #define UNUSED ATTRIBUTE ((unused))
37
38 /* Marks a function that will never return. */
39 #define NO_RETURN ATTRIBUTE ((noreturn))
40
41 /* Mark a function as taking a printf- or scanf-like format
42    string as its FMT'th argument and that the FIRST'th argument
43    is the first one to be checked against the format string. */
44 #define PRINTF_FORMAT(FMT, FIRST) ATTRIBUTE ((format (printf, FMT, FIRST)))
45 #define SCANF_FORMAT(FMT, FIRST) ATTRIBUTE ((format (scanf, FMT, FIRST)))
46
47 /* Tells the compiler that a function may be treated as if any
48    non-`NULL' pointer it returns cannot alias any other pointer
49    valid when the function returns. */
50 #if __GNUC__ > 2
51 #define MALLOC_LIKE ATTRIBUTE ((malloc))
52 #else
53 #define MALLOC_LIKE
54 #endif
55
56 /* This attribute was added in GCC 4.0. */
57 #if __GNUC__ >= 4
58 #define WARN_UNUSED_RESULT ATTRIBUTE ((warn_unused_result))
59 #else
60 #define WARN_UNUSED_RESULT
61 #endif
62
63 /* This attribute indicates that the function does not examine
64    any values except its arguments, and has no effects except the
65    return value.  A function that has pointer arguments and
66    examines the data pointed to must _not_ be declared
67    `const'.  */
68 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)
69 #define CONST_FUNCTION ATTRIBUTE ((const))
70 #else
71 #define CONST_FUNCTION
72 #endif
73
74 /* This attribute indicates that the function has no effects
75    except the return value and its return value depends only on
76    the parameters and/or global variables. */
77 #if __GNUC__ > 2
78 #define PURE_FUNCTION ATTRIBUTE ((pure))
79 #else
80 #define PURE_FUNCTION
81 #endif
82
83 #endif /* compiler.h */