public inbox for ecos-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug 1001915] New: Invalid assert definition
@ 2013-11-13 10:45 bugzilla-daemon
0 siblings, 0 replies; 2+ messages in thread
From: bugzilla-daemon @ 2013-11-13 10:45 UTC (permalink / raw)
To: unassigned
Please do not reply to this email, use the link below.
http://bugs.ecos.sourceware.org/show_bug.cgi?id=1001915
Bug ID: 1001915
Summary: Invalid assert definition
Product: eCos
Version: 3.0
Target: All
Architecture/Host All
OS:
Status: UNCONFIRMED
Severity: major
Priority: low
Component: POSIX
Assignee: unassigned@bugs.ecos.sourceware.org
Reporter: jsetoain@ucm.es
CC: ecos-bugs@ecos.sourceware.org
According to ISO C, the assert macro must be an expression but it is defined as
an statement (do { } while(0)). This definition causes trouble in several
situation where "assert" is used as an expression.
From:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/assert.html
"The assert() macro shall insert diagnostics into programs; it shall expand to
a void expression."
Right now it is defined as follows:
# define assert( __bool ) \
do { \
if (0 == (__bool)) { \
fprintf( stderr, "User assertion failed: \"%s\", at %s:%d\n", \
#__bool, __FILE__, __LINE__); \
abort(); \
} \
} while(0)
I propose changing it to something like this:
# define assert(__bool) \
((__bool) \
? (void)(0) \
: assert_failed(#__bool, __FILE__, __LINE__)
And then define assert_failed as something like:
void assert_failed(const char* assertion, const char* file, const char* line )
{
fprintf( stderr, "User assertion failed: \"%s\", at %s:%d\n",
assertion, file, line );
abort();
}
This way, assert always evaluates to a void expression, as demanded by the
standard.
(PS: The whole fix would take changes in other macros, I'm just illustrating
the problem and the solution).
--
You are receiving this mail because:
You are the assignee for the bug.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug 1001915] New: Invalid assert definition
@ 2013-11-13 10:45 bugzilla-daemon
0 siblings, 0 replies; 2+ messages in thread
From: bugzilla-daemon @ 2013-11-13 10:45 UTC (permalink / raw)
To: ecos-bugs
Please do not reply to this email, use the link below.
http://bugs.ecos.sourceware.org/show_bug.cgi?id=1001915
Bug ID: 1001915
Summary: Invalid assert definition
Product: eCos
Version: 3.0
Target: All
Architecture/Host All
OS:
Status: UNCONFIRMED
Severity: major
Priority: low
Component: POSIX
Assignee: unassigned@bugs.ecos.sourceware.org
Reporter: jsetoain@ucm.es
CC: ecos-bugs@ecos.sourceware.org
According to ISO C, the assert macro must be an expression but it is defined as
an statement (do { } while(0)). This definition causes trouble in several
situation where "assert" is used as an expression.
From:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/assert.html
"The assert() macro shall insert diagnostics into programs; it shall expand to
a void expression."
Right now it is defined as follows:
# define assert( __bool ) \
do { \
if (0 == (__bool)) { \
fprintf( stderr, "User assertion failed: \"%s\", at %s:%d\n", \
#__bool, __FILE__, __LINE__); \
abort(); \
} \
} while(0)
I propose changing it to something like this:
# define assert(__bool) \
((__bool) \
? (void)(0) \
: assert_failed(#__bool, __FILE__, __LINE__)
And then define assert_failed as something like:
void assert_failed(const char* assertion, const char* file, const char* line )
{
fprintf( stderr, "User assertion failed: \"%s\", at %s:%d\n",
assertion, file, line );
abort();
}
This way, assert always evaluates to a void expression, as demanded by the
standard.
(PS: The whole fix would take changes in other macros, I'm just illustrating
the problem and the solution).
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-11-13 10:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-13 10:45 [Bug 1001915] New: Invalid assert definition bugzilla-daemon
2013-11-13 10:45 bugzilla-daemon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).