Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/include/util/cassert.h need to be fixed.

0001 /*                    The Quest Operating System
0002  *  Copyright (C) 2005-2010  Richard West, Boston University
0003  *
0004  *  This program is free software: you can redistribute it and/or modify
0005  *  it under the terms of the GNU General Public License as published by
0006  *  the Free Software Foundation, either version 3 of the License, or
0007  *  (at your option) any later version.
0008  *
0009  *  This program is distributed in the hope that it will be useful,
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *  GNU General Public License for more details.
0013  *
0014  *  You should have received a copy of the GNU General Public License
0015  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0016  */
0017 
0018 #ifndef _UTIL_CASSERT_H_
0019 #define _UTIL_CASSERT_H_
0020 
0021 /* http://stackoverflow.com/questions/807244/c-compiler-asserts-how-to-implement */
0022 
0023 /** A compile time assertion check.
0024  *
0025  *  Validate at compile time that the predicate is true without
0026  *  generating code. This can be used at any point in a source file
0027  *  where typedef is legal.
0028  *
0029  *  On success, compilation proceeds normally.
0030  *
0031  *  On failure, attempts to typedef an array type of negative size. The
0032  *  offending line will look like
0033  *      typedef assertion_failed_file_h_42[-1]
0034  *  where file is the content of the second parameter which should
0035  *  typically be related in some obvious way to the containing file
0036  *  name, 42 is the line number in the file on which the assertion
0037  *  appears, and -1 is the result of a calculation based on the
0038  *  predicate failing.
0039  *
0040  *  \param predicate The predicate to test. It must evaluate to
0041  *  something that can be coerced to a normal C boolean.
0042  *
0043  *  \param file A sequence of legal identifier characters that should
0044  *  uniquely identify the source file in which this condition appears.
0045  */
0046 #define CASSERT(predicate, file) _impl_CASSERT_LINE(predicate,__LINE__,file)
0047 
0048 #define _impl_PASTE(a,b) a##b
0049 #define _impl_CASSERT_LINE(predicate, line, file) \
0050     typedef char _impl_PASTE(assertion_failed_##file##_,line)[2*!!(predicate)-1];
0051 
0052 #endif
0053 
0054 /*
0055  * Local Variables:
0056  * indent-tabs-mode: nil
0057  * mode: C
0058  * c-file-style: "gnu"
0059  * c-basic-offset: 2
0060  * End:
0061  */
0062 
0063 /* vi: set et sw=2 sts=2: */