public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Detlev Zundel <dzu@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2] arm: Correct build error introduced by getenv_ulong() patch
Date: Wed, 09 Nov 2011 14:45:03 +0100	[thread overview]
Message-ID: <m2wrb9beao.fsf@ohwell.denx.de> (raw)
In-Reply-To: <CALButCKrMCsKMx7+kD5Dd22h8w+WboFt7zBqMNYDvha2kBjsSg@mail.gmail.com> (Graeme Russ's message of "Wed, 9 Nov 2011 10:18:01 +1100")

Hi Graeme,

> Hi Wolfgang
>
> On Wed, Nov 9, 2011 at 9:49 AM, Wolfgang Denk <wd@denx.de> wrote:
>> Dear Simon Glass,
>>
>> In message <CAPnjgZ15f_gva5+MM1Em-L2sMxt1WAATxqiKUHOQAT893t9MMw@mail.gmail.com> 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

  reply	other threads:[~2011-11-09 13:45 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-24  0:14 [U-Boot] [PATCH] arm: Correct build error introduced by getenv_ulong() patch Simon Glass
2011-10-24  3:44 ` [U-Boot] [PATCH v2] " Simon Glass
2011-10-24 19:13   ` Wolfgang Denk
2011-10-25  6:52     ` Albert ARIBAUD
2011-10-25  7:50       ` Wolfgang Denk
2011-10-25 18:21         ` Albert ARIBAUD
2011-10-25 18:26           ` Simon Glass
2011-10-25 19:36           ` Wolfgang Denk
2011-10-25 19:41             ` Simon Glass
2011-10-31  0:44   ` Mike Frysinger
2011-10-31 21:06     ` Simon Glass
2011-10-31 21:40       ` Mike Frysinger
2011-11-08  9:20         ` Detlev Zundel
2011-11-08 15:57           ` Simon Glass
2011-11-08 19:46             ` Albert ARIBAUD
2011-11-08 22:28               ` Simon Glass
2011-11-08 22:49                 ` Wolfgang Denk
2011-11-08 23:18                   ` Graeme Russ
2011-11-09 13:45                     ` Detlev Zundel [this message]
2011-11-09 14:30                       ` Simon Glass
2011-11-09 14:11                   ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2wrb9beao.fsf@ohwell.denx.de \
    --to=dzu@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox