On 19-04-08 02:34, Mrunal Gawade wrote:

Does Linux kernel has assert?

A few dozen of them...

I am trying to port a user land program with asserts and want to use them
in kernel too. What is the header file in which its declared, if it is. I
tried "grep" and other commands but could not find.

The most pronounced thing the userland assert does is abort the program (when compiled without NDEBUG, that is) and since kernel code is not "a program" you'll have to react differently to exceptional conditions.

If you insist, you could translate the assserts into WARN_ON or BUG_ON invocations, perhaps even via macro for a fairly close analogy:

#ifndef NDEBUG
#  define assert(condition) BUG_ON(!(condition))
#else
#  define assert(condition)
#endif

This kind of code is generally frowned upon though when "condition" isn't something which isn't/shouldn't really be absolutely true always; it's obviously a rather unsubtle form of error handling if not.

You could also choose to just print an error message (WARN_ON(!(condition))) and fix things up or do whetever else suits your fancy. The important thing to realize is that there's no pure analogy due to the difference between kernel code and "a program".

Rene.

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to [EMAIL PROTECTED]
Please read the FAQ at http://kernelnewbies.org/FAQ

Reply via email to