Thread View: gnu.g++.lib.bug
2 messages
2 total messages
Started by Jesper Joergensen [ris]
Wed, 20 Dec 1989 16:51
Possible bug in <assert.h> (version 1.36.1)
Author: Jesper Joergensen [ris]
Date: Wed, 20 Dec 1989 16:51
Date: Wed, 20 Dec 1989 16:51
47 lines
2071 bytes
2071 bytes
Hello Denmark calling,
I've just considered using the assertion macros in <assert.h> and was
inspecting the definitions (version 1.36.1) out of pure curiosity. I
found something which seemed strange to me and decided to report it,
since it might be a bug.
The definitions effectuated when NDEBUG is defined are:
#define assert(ignore)
#define assertval(ex) (ex)
which tells me that assertval is intended for use in an expression,
since this dummy definition returns the value of the test expression
itself, while assert is meant for use as a statement.
The definition of assertval in effect when NDEBUG is undefined is:
#define assertval(ex) \
((ex) ? 1 : \
(__eprintf("Failed assertion " #ex " at line %d of `%s'.\n",\
__LINE__, __FILE__), abort (), 0))
but this macro doesn't return the exact value of the given expression
itself, only an indication that the expression is true. Besides that it is
completely identical to assert in this case. If assert is meant for
use as a statement, then why isn't it defined as a regular if statement.
Is this an error or is it intentional and if so why ?? (side effects ??)
By the way: I can see what NDEBUG is used for, but is it for user control
or controlled by the system/compiler ?? Is it used for anything else ??
That's all for now, I'll return some other time
Marry Christmas and a Happy new year
Jesper Jorgensen (known as 'JJ the famous')
Research associate
Department of Computer Science
Technical University of Denmark
DK-2800 Lyngby
DENMARK
Possible bug in <assert.h> (version 1.36.1)
Author: Doug Lea
Date: Fri, 29 Dec 1989 14:56
Date: Fri, 29 Dec 1989 14:56
24 lines
1213 bytes
1213 bytes
Sorry for the delayed reply -- I've been away.
Well, it's less of a bug than a limitation: if you were to change assertval
from
#define assertval(ex) \
((ex) ? 1 : \
(__eprintf("Failed assertion " #ex " at line %d of `%s'.\n",\
__LINE__, __FILE__), abort (), 0))
to
#define assertval(ex) \
((ex) ? (ex) : \
(__eprintf("Failed assertion " #ex " at line %d of `%s'.\n",\
__LINE__, __FILE__), abort (), 0))
then it would evaluate ex twice. While it IS possible to overcome
this with gcc/g++ expression-returning compound statements, I didn't
do this, in order to be conservative. Do thing it is worth doing?
-Doug
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads