[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: prom-libc: __assert problem?



On Fri, Sep 05, 2003 at 04:08:52PM -0400, Warren A. Layton wrote:
> I was just going through the prom-libc code and I still think that the
> __assert function isn't correct.
> 
> Is the __assert function supposed to behave like the assert function from
> <assert.h>? In __assert, we pass an assertion (const char *), but it is
> never checked to make sure that it is true or false. If we do indeed
> need to verify the assertion statement, we will probably require an if
> statement in this function. As it stands, my limited testing of the
> function has it aborting regardless.
> 
> Then again, if this isn't the purpose of this function, please correct
> me.

the purpose of __assert() is to print the message and abort, its not
responsible for the test.

see assert.h:

/* This prints an "Assertion failed" message and aborts.  */
extern void __assert(const char *assertion, const char *file,
                     unsigned int line, const char *function)
                     __attribute__ ((__noreturn__));

#define assert(assertion) \
              ((void)((assertion) ? 0 : (__assert(__STR(assertion), \
              __FILE__, __LINE__, __PRETTY_FUNCTION__), 0)))

so the macro assert() tests the assertion, if its false it calls
__assert with the first arg being a stringified version of the
assertion, the filename, line number, and function name as arguments.

-- 
Ethan Benson
http://www.alaska.net/~erbenson/

Attachment: pgp00001.pgp
Description: PGP signature