42c804470c
It's common knowledge to not cause any writes inside an assertion condition since they are not guaranteed to be executed, so we can still evaluate them and cast to void, which the compiler can optimize away. It's better than having a `(void)rc;` for every variable that is only used in assertions.
51 lines
1.7 KiB
C
51 lines
1.7 KiB
C
/* This file is part of libbrandt.
|
|
* Copyright (C) 2016 GNUnet e.V.
|
|
*
|
|
* libbrandt is free software: you can redistribute it and/or modify it under
|
|
* the terms of the GNU General Public License as published by the Free Software
|
|
* Foundation, either version 3 of the License, or (at your option) any later
|
|
* version.
|
|
*
|
|
* libbrandt is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* libbrandt. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/**
|
|
* @file util.h
|
|
* @brief \todo
|
|
* @author Markus Teich
|
|
*/
|
|
|
|
#ifndef _BRANDT_UTIL_H
|
|
#define _BRANDT_UTIL_H
|
|
|
|
void eprintf(const char *fmt, ...);
|
|
void weprintf(const char *fmt, ...);
|
|
|
|
# undef brandt_assert
|
|
# undef brandt_assert_perror
|
|
# undef brandt_assert_gpgerr
|
|
|
|
#ifdef NDEBUG
|
|
|
|
# define brandt_assert(expr) ((void)(expr))
|
|
# define brandt_assert_perror(errnum) ((void)(errnum))
|
|
# define brandt_assert_gpgerr(errnum) ((void)(errnum))
|
|
|
|
#else
|
|
|
|
# define brandt_assert(expr) ((expr) ? (void)(0) : \
|
|
eprintf("Assertion failed in file %s line %d function %s: %s", __FILE__, __LINE__, __PRETTY_FUNCTION__, (#expr)))
|
|
# define brandt_assert_perror(errnum) (!(errnum) ? (void)(0) : \
|
|
eprintf("Assertion failed in file %s line %d function %s:", __FILE__, __LINE__, __PRETTY_FUNCTION__))
|
|
# define brandt_assert_gpgerr(errnum) (!(errnum) ? (void)(0) : \
|
|
eprintf("Assertion failed in file %s line %d function %s: %s", __FILE__, __LINE__, __PRETTY_FUNCTION__, gcry_strerror((errnum))))
|
|
|
|
#endif
|
|
|
|
#endif
|