[U-Boot] [PATCH] Add assert() for debug assertions

Wolfgang Denk wd at denx.de
Wed Jun 22 23:56:49 CEST 2011


Dear Mike Frysinger,

In message <201106221723.27679.vapier at gentoo.org> you wrote:
>
> the trouble with ifdef magic like this is that errors/warnings can be=20
> introduced when DEBUG isnt defined, and then only noticed when DEBUG is=20
> defined.  so how about:
> 
> #ifdef DEBUG
> # define _DEBUG 1
> #else
> # define _DEBUG 2

1 and 2?  You don't happen to mean 1 and 0 ?

> #define assert(x) \
> 	do { \
> 		if ((x) && _DEBUG) \
> 			printf("%s:%s():%i: assertion failure: %s\n", \
> 				__FILE__, __func__, __LINE__, #x); \
> 	} while (0)

This way the code will _always_ be compiled in.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"In the long run, every program becomes rococo, and then rubble."
- Alan Perlis


More information about the U-Boot mailing list