|
|
1.1 root 1: #ifndef __COMMON_FEATURE_H__
2: #define __COMMON_FEATURE_H__
3:
4: /*
5: * This header file deals with some minor complications that exist in the
6: * world of feature-tests. Standard style for new code is to use the simpler
7: * and more powerful #if test rather than the cumbersome and less useful
8: * #ifdef/#ifndef tests that untutored programmers gravitate to.
9: *
10: * However, this is made more difficult by historical problems, and some
11: * latitude extended to users. For example, while POSIX.1 introduces a
12: * feature-test macro such as _POSIX_SOURCE, no value for this macro was
13: * recommended, and so users typically #define this symbol to have no value,
14: * making the #if form of feature-test more complex. Conversely, the ISO C
15: * standard mandates a value for __STDC__, but users have uniformly ignored
16: * this fact.
17: *
18: * This file mutates definitions of well-known feature tests so that the #if
19: * form of test can be used universally. This means using several tricks to
20: * detect such things as symbols with empty values, but such tricks break down
21: * if users are perverse and #define symbols like _POSIX_SOURCE with values
22: * that are strings or which cannot be evaluated. For such symbols, we have
23: * an option which will simply force the feature to value 1 rather than trying
24: * to be clever. This means that some utility is lost (in the sense that
25: * features cannot have graduated values for purposes such as selecting
26: * versions) so this is off by default.
27: */
28:
29: #define __EMPTY(x) ((1 - x - 1) == 2)
30:
31: #define __UNDEFINED_OR_EMPTY(x) (! defined (x) || __EMPTY (x))
32:
33: #ifdef _FORCE_TO_ONE
34: # undef _FORCE_TO_ONE
35: # define _FORCE_TO_ONE 1
36: #endif
37:
38: #if defined (_POSIX_SOURCE)
39: # if _FORCE_TO_ONE
40:
41: # undef _POSIX_SOURCE
42: # define _POSIX_SOURCE 1
43:
44: # elif __EMPTY (_POSIX_SOURCE)
45:
46: # undef _POSIX_SOURCE
47: # define _POSIX_SOURCE 1
48:
49: #endif
50: #endif
51:
52:
53:
54: /*
55: * We have a feature-test _STDC_SOURCE analagous to _POSIX_SOURCE which
56: * selects a minimal ISO C compilation environment. This is mutually exclusive
57: * with _POSIX_SOURCE. We could either complain or do something tricky like
58: * select the one with the highest value.
59: */
60:
61: #if _STDC_SOUCE || _POSIX_SOURCE
62: # if _STDC_SOURCE > _POSIX_SOURCE
63:
64: # undef _POSIX_SOURCE
65:
66: # elif _STDC_SOURCE < _POSIX_SOURCE
67:
68: # undef _STDC_SOURCE
69:
70: # else
71:
72: # error You cannot select both _POSIX_SOURCE and _STDC_SOURCE in a compilation
73:
74: # endif
75: #endif
76:
77: /*
78: * For Coherent: avoid the use of COHERENT as a feature-test, use __COHERENT__
79: * instead.
80: */
81:
82: #ifdef KERNEL
83:
84: #undef KERNEL
85: #undef __KERNEL__
86: #define __KERNEL__ 1
87:
88: #endif
89:
90: #ifdef COHERENT
91:
92: #undef __COHERENT__
93: #define __COHERENT__ 1
94:
95: #endif
96:
97: /*
98: * The MWC port of GCC botches -ansi mode by not defining _I386; here we put
99: * it back in again. This also serves to define _I386 for those systems that
100: * traditionally just define "i386".
101: */
102:
103: #if __GNUC__ && (defined (i386) || __COHERENT__) && ! defined (_I386)
104: # define _I386 1
105: #endif
106:
107: #endif /* ! defined (__COMMON_FEATURE_H__) */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.