assert.h revision 199767f8919635c4928607450d9e0abb932109ce
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright/*-
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * Copyright (c) 1992, 1993
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * The Regents of the University of California. All rights reserved.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * (c) UNIX System Laboratories, Inc.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * All or some portions of this file are derived from material licensed
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * to the University of California by American Telephone and Telegraph
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * Co. or Unix System Laboratories, Inc. and are reproduced herein with
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * the permission of UNIX System Laboratories, Inc.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright *
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * Redistribution and use in source and binary forms, with or without
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * modification, are permitted provided that the following conditions
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * are met:
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * 1. Redistributions of source code must retain the above copyright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * notice, this list of conditions and the following disclaimer.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * 2. Redistributions in binary form must reproduce the above copyright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * notice, this list of conditions and the following disclaimer in the
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * documentation and/or other materials provided with the distribution.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * 3. Neither the name of the University nor the names of its contributors
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * may be used to endorse or promote products derived from this software
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * without specific prior written permission.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright *
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * SUCH DAMAGE.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright *
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * @(#)assert.h 8.2 (Berkeley) 1/21/94
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * $FreeBSD$
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright#include <sys/cdefs.h>
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright/*
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * Unlike other ANSI header files, <assert.h> may usefully be included
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * multiple times, with and without NDEBUG defined.
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright */
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier#undef assert
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright#undef _assert
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright#ifdef NDEBUG
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright#define assert(e) ((void)0)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright#define _assert(e) ((void)0)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright#else
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright#define _assert(e) assert(e)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright#define assert(e) ((e) ? (void)0 : __assert(__func__, __FILE__, \
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright __LINE__, #e))
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright#endif /* NDEBUG */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright#ifndef _ASSERT_H_
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright#define _ASSERT_H_
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright/*
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * Static assertions. In principle we could define static_assert for
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * C++ older than C++11, but this breaks if _Static_assert is
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * implemented as a macro.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright *
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * C++ template parameters may contain commas, even if not enclosed in
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * parentheses, causing the _Static_assert macro to be invoked with more
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright * than two parameters.
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright#if __ISO_C_VISIBLE >= 2011 && !defined(__cplusplus)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright#define static_assert _Static_assert
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright#endif
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright__BEGIN_DECLS
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightvoid __assert(const char *, const char *, int, const char *) __dead2;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright__END_DECLS
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright#endif /* !_ASSERT_H_ */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright