From mboxrd@z Thu Jan 1 00:00:00 1970 From: Detlev Zundel Date: Wed, 09 Nov 2011 14:45:03 +0100 Subject: [U-Boot] [PATCH v2] arm: Correct build error introduced by getenv_ulong() patch In-Reply-To: (Graeme Russ's message of "Wed, 9 Nov 2011 10:18:01 +1100") References: <1319415273-3915-1-git-send-email-sjg@chromium.org> <201110302044.09233.vapier@gentoo.org> <201110311740.04957.vapier@gentoo.org> <4EB98726.8090104@aribaud.net> <20111108224945.8552D189301F@gemini.denx.de> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Graeme, > Hi Wolfgang > > On Wed, Nov 9, 2011 at 9:49 AM, Wolfgang Denk wrote: >> Dear Simon Glass, >> >> In message you wrote: >>> >>> This discussion was regarding the need to #ifdef the variable declaration, viz: >>> >>> #if defined(THING1) || defined(THING2) >>> const char *cat; >>> #endif >>> >>> ... >>> >>> >>> #ifdef THING1 >>> cat = getenv("cat"); >>> >>> send_back(cat); >>> #endif >>> >>> .... >>> >>> #ifdef THING2 >>> cat = check_outside("cat"); >>> >>> if (cat) >>> wibble(cat); >>> #endif >>> >>> >>> and whether the top bit would be better as: >>> >>> __maybe_unused const char *cat; >>> >>> But more generally, lots of #ifdefs do make the code harder to read, >>> and potentially more brittle in the face of config changes. >> >> I would like to see only a minimal number of "__maybe_unused" in the >> code - in cases, where this is the way that hurts least. >> >> In the examples above, it might be better to use local blocks, like: >> >> #ifdef THING1 >> { >> const char *cat = getenv("cat"); >> >> send_back(cat); >> } >> #endif > > I honestly think most of these cases can be factored out into functions. > The compiler should inline them anyway so the overhead should be zero. > The various board.c files are a prime example of where this should be > done as a matter of principle to reduce the complexity and lenght of > the primary function anyway I would even like to skip the ifdefs completely. Modern compilers with dead code elimination will completely do away unneeded code _but still do syntax checks on the parts every time_. So maybe we should simply try to use if (THING1) { ... } I know that this would need an "#ifdef THING1 1" but errors in this would be caught immediately (and not only under a certain combination of ifdefs) by the compiler so I don't think this is a problem. I don't know how often I repeat my mantra, but every ifdef doubles the number of _different source codes_ that we deal with. Cheers Detlev -- Lotus Notes (GUI): Run away from it. -- linux/Documentation/email-clients.txt -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de