libtranscript
/home/gertjan/projects/transcript/src/static_assert.h
00001 /* Copyright (C) 2011 G.P. Halkes
00002    This program is free software: you can redistribute it and/or modify
00003    it under the terms of the GNU General Public License version 3, as
00004    published by the Free Software Foundation.
00005 
00006    This program is distributed in the hope that it will be useful,
00007    but WITHOUT ANY WARRANTY; without even the implied warranty of
00008    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00009    GNU General Public License for more details.
00010 
00011    You should have received a copy of the GNU General Public License
00012    along with this program.  If not, see <http://www.gnu.org/licenses/>.
00013 */
00014 
00015 #ifndef STATIC_ASSERT
00016 #define STATIC_ASSERT
00017 
00018 /* The static_assert is achieved by creating a struct definition which contains
00019    an array of negative size if the condition is false. To prevent multiple
00020    static assertions to define the same struct, the line number on which the
00021    assertion name of the struct is made is appended to the name of the struct.
00022    However, to do this we need another layer of indirection because the
00023    arguments of ## are not expanded before pasting.
00024 */
00025 #define __static_assert(_condition, _line) struct __static_assert_##_line { int static_assert_failed[_condition ? 1 : -1]; }
00026 #define _static_assert(_condition, _line) __static_assert(_condition, _line)
00027 #define static_assert(_condition) _static_assert(_condition, __LINE__)
00028 
00029 #endif
 All Data Structures Variables