All of lore.kernel.org
 help / color / mirror / Atom feed
From: Albert ARIBAUD <albert.u.boot@aribaud.net>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v4 0/8] Provide a mechanism to avoid using #ifdef everywhere
Date: Thu, 7 Nov 2013 10:20:18 +0100	[thread overview]
Message-ID: <20131107102018.61bfbdea@lilith> (raw)
In-Reply-To: <20131106072444.055753811E0@gemini.denx.de>

Hi Wolfgang,

On Wed, 06 Nov 2013 08:24:44 +0100, Wolfgang Denk <wd@denx.de> wrote:

> Dear Simon Glass,
> 
> In message <1382800457-26608-1-git-send-email-sjg@chromium.org> you wrote:
> > Many parts of the U-Boot code base are sprinkled with #ifdefs. This makes
> > different boards compile different versions of the source code, meaning
> > that we must build all boards to check for failures. It is easy to misspell
> > an #ifdef and there is not as much checking of this by the compiler. Multiple
> > dependent #ifdefs are harder to do than with if..then..else. Variable
> > declarations must be #idefed as well as the code that uses them, often much
> > later in the file/function. #ifdef indents don't match code indents and
> > have their own separate indent feature. Overall, excessive use of #idef
> > hurts readability and makes the code harder to modify and refactor. For
> > people coming newly into the code base, #ifdefs can be a big barrier.
> > 
> > The use of #ifdef in U-Boot has possibly got a little out of hand. In an
> > attempt to turn the tide, this series includes a patch which provides a way
> > to make CONFIG macros available to C code without using the preprocessor.
> > This makes it possible to use standard C conditional features such as
> > if/then instead of #ifdef. A README update exhorts compliance.
> 
> As mentioned before, I'm really interested in seeing something like
> this going into mainline, but I have some doubts about the actual
> implementation.
> 
> To summarize:  Your current proposal was to convert code snippets
> like this:
> 
> 	#ifdef CONFIG_VERSION_VARIABLE
> 		setenv("ver", version_string);  /* set version variable */
> 	#endif
> 
> into
> 
> 	if (autoconf_version_variable())
> 		setenv("ver", version_string);  /* set version variable */
> 
> By chance I ran about "include/linux/kconfig.h" in the Linux kernel
> tree, which provides (among other things) the IS_ENABLED() macro that
> implements essentially the very same feature.  Using this, the same
> code would be written as:
> 
> 	if (IS_ENABLED(CONFIG_VERSION_VARIABLE))
> 		setenv("ver", version_string);  /* set version variable */
> 
> I agree that this does not solve some of the isses that have been
> raised about this change (indentation level increses - which may in
> turn require reformatting of bigger parts of the code; code becomes
> less readable), but on the other hand it avoids the need for a new
> autoconf header file, and it should be possible to introduce this
> easily step by step.
> 
> And I really like the idea of re-using existing code that is already
> known to Linux hackers, especially as we we are currently having our
> eyes on the Kconfig stuff anyway.
> 
> What do you think?

Agreed on the whole -- plus, introducing indentation in configuration
option testing will make it easier to spot and understand nested
configuration conditionals.
 
> Best regards,
> 
> Wolfgang Denk
> 


Amicalement,
-- 
Albert.

  parent reply	other threads:[~2013-11-07  9:20 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-26 15:14 [U-Boot] [PATCH v4 0/8] Provide a mechanism to avoid using #ifdef everywhere Simon Glass
2013-10-26 15:14 ` [U-Boot] [PATCH v4 1/8] Implement autoconf header file Simon Glass
2013-11-10 19:47   ` Marek Vasut
2013-10-26 15:14 ` [U-Boot] [PATCH v4 2/8] main: Use autoconf for boot retry feature Simon Glass
2013-10-26 15:14 ` [U-Boot] [PATCH v4 3/8] main: Remove CONFIG #ifdefs from the abortboot() code Simon Glass
2013-10-26 15:14 ` [U-Boot] [PATCH v4 4/8] main: Use autoconf to remove #ifdefs around process_boot_delay() Simon Glass
2013-10-26 15:14 ` [U-Boot] [PATCH v4 5/8] main: Use autoconf for boot_delay code Simon Glass
2013-10-26 15:14 ` [U-Boot] [PATCH v4 6/8] main: Use autoconf for parser selection Simon Glass
2013-10-28 14:21   ` Michal Simek
2013-10-26 15:14 ` [U-Boot] [PATCH v4 7/8] main: Use autoconf in command line reading Simon Glass
2013-10-26 15:14 ` [U-Boot] [PATCH v4 8/8] main: Use autoconf in main_loop() Simon Glass
2013-10-28 14:44 ` [U-Boot] [PATCH v4 0/8] Provide a mechanism to avoid using #ifdef everywhere Wolfgang Denk
2013-10-28 15:32   ` Tom Rini
2013-10-28 20:31     ` Simon Glass
2013-11-06  7:24 ` Wolfgang Denk
2013-11-06  8:30   ` Stefan Roese
2013-11-07  9:20   ` Albert ARIBAUD [this message]
2013-11-10  4:24   ` Simon Glass
2013-11-10 12:58     ` Wolfgang Denk
2014-01-14 10:11     ` Detlev Zundel
2014-01-15 18:11       ` Simon Glass
2014-01-17 15:13         ` Detlev Zundel
2014-01-26 20:58           ` Simon Glass
  -- strict thread matches above, loose matches on Subject: below --
2013-06-17 14:44 Simon Glass
2013-06-23  7:29 ` Albert ARIBAUD
2013-06-25  0:52   ` Simon Glass
2013-06-27  7:04     ` Albert ARIBAUD
2013-06-27  7:15       ` 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=20131107102018.61bfbdea@lilith \
    --to=albert.u.boot@aribaud.net \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.