/*1* Copyright (c) 2003, 2006, 2008, 20092* The President and Fellows of Harvard College.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. Neither the name of the University nor the names of its contributors13* may be used to endorse or promote products derived from this software14* without specific prior written permission.15*16* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE20* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*/2829#ifndef _CDEFS_H_30#define _CDEFS_H_3132/*33* Some miscellaneous C language definitions and related matters.34*/353637/*38* Build-time assertion. Doesn't generate any code. The error message39* on failure is less than ideal, but you can't have everything.40*/41#define COMPILE_ASSERT(x) ((void)sizeof(struct { unsigned : ((x)?1:-1); }))424344/*45* Tell GCC how to check printf formats.46*/47#ifdef __GNUC__48#define __PF(a,b) __attribute__((__format__(__printf__, a, b)))49#else50#define __PF(a,b)51#endif525354/*55* Material for supporting inline functions.56*57* A function marked inline can be handled by the compiler in three58* ways: in addition to possibly inlining into the code for other59* functions, the compiler can (1) generate a file-static out-of-line60* copy of the function, (2) generate a global out-of-line copy of the61* function, or (3) generate no out-of-line copy of the function.62*63* None of these alone is thoroughly satisfactory. Since an inline64* function may or may not be inlined at the compiler's discretion, if65* no out-of-line copy exists the build may fail at link time with66* undefined symbols. Meanwhile, if the compiler is told to generate a67* global out-of-line copy, it will generate one such copy for every68* source file where the inline definition is visible; since inline69* functions tend to appear in header files, this leads to multiply70* defined symbols and build failure. The file-static option isn't71* really an improvement, either: one tends to get compiler warnings72* about inline functions that haven't been used, which for any73* particular source file tends to be at least some of the ones that74* have been defined. Furthermore, this method leads to one75* out-of-line copy of the inline function per source file that uses76* it, which not only wastes space but makes debugging painful.77*78* Therefore, we use the following scheme.79*80* In the header file containing the inline functions for the module81* "foo", we put82*83* #ifndef FOO_INLINE84* #define FOO_INLINE INLINE85* #endif86*87* where INLINE selects the compiler behavior that does *not* generate88* an out-of-line version. Then we define the inline functions89* themselves as FOO_INLINE. This allows the compiler to inline the90* functions anywhere it sees fit with a minimum of hassles. Then,91* when compiling foo.c, before including headers we put92*93* #define FOO_INLINE // empty94*95* which causes the inline functions to appear as ordinary function96* definitions, not inline at all, when foo.c is compiled. This97* ensures that an out-of-line definition appears, and furthermore98* ensures that the out-of-line definition is the same as the inline99* definition.100*101* The situation is complicated further because gcc is not compliant102* with the C standard. In C99, "inline" means "do not generate an103* out-of-line copy" and "extern inline" means "generate a global104* out-of-line copy". In gcc, the meanings are reversed. In gcc105* versions later than the one OS/161 currently uses, the standard106* behavior can be requested; if so, __GNUC_STDC_INLINE__ is defined.107* There does not appear to be any way to select this behavior with108* gcc 4.1; however, the following definitions should be future-proof.109*110* (Note that inline functions that appear only within a single source111* file can safely be declared "static inline".)112*/113#if defined(__GNUC__) && !defined(__GNUC_STDC_INLINE__)114/* gcc's non-C99 inline semantics */115#define INLINE extern inline116117#elif defined(__STDC__) && __STDC_VERSION__ >= 199901L118/* C99 */119#define INLINE inline120121#else122/* something else; static inline is safest */123#define INLINE static inline124#endif125126127#endif /* _CDEFS_H_ */128129130