From: Wolfgang Denk Date: Wed, 22 Jun 2011 23:56:49 +0200 Subject: [U-Boot] [PATCH] Add assert() for debug assertions In-Reply-To: <201106221723.27679.vapier@gentoo.org> References: <1308776689-28115-1-git-send-email-sjg@chromium.org> <201106221723.27679.vapier@gentoo.org> Message-ID: <20110622215649.BBB0D17E88A5@gemini.denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Dear Mike Frysinger, In message <201106221723.27679.vapier@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