[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: assert.h replacement
From: |
Ben Pfaff |
Subject: |
Re: assert.h replacement |
Date: |
Tue, 04 Mar 2008 08:18:33 -0800 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) |
Eric Blake <address@hidden> writes:
> Simon Josefsson <simon <at> josefsson.org> writes:
>> Couldn't a replacement assert.h look like:
>>
>> #include <stdio.h>
>> #include "progname.h"
>>
>> #ifdef NDEBUG
>> # define assert(e) ((void) 0)
>> #else
>> # define assert(e) \
>> if (!(e)) { \
>> fprintf (stderr, "%s: %s: %s: %s: Assertion failed.\n", \
>> program_name, __FILE__, __LINE__, __func__); \
>
> Not quite. Using if(){} will break if assert occurs as the sole statement
> inside another if-else pair - use while(){} or ?: instead. [...]
The C standard says that the assert macro expands to a void
expression, not to a statement, so a while or do-while loop is
out.
--
Ben Pfaff
http://benpfaff.org
- Re: __func__, (continued)
- Re: __func__, Eric Blake, 2008/03/04
- Re: __func__, Simon Josefsson, 2008/03/06
- Re: __func__, Jim Meyering, 2008/03/06
- Re: __func__, Simon Josefsson, 2008/03/06
- Re: __func__, Simon Josefsson, 2008/03/06
- Re: __func__, Bruno Haible, 2008/03/06
Re: __func__, Simon Josefsson, 2008/03/03
Re: __func__, Simon Josefsson, 2008/03/03