[U-Boot] declaring and initializing variables

Timur Tabi timur at tabi.org
Tue Oct 1 03:17:38 CEST 2013


On Mon, Sep 30, 2013 at 7:04 PM, York Sun <yorksun at freescale.com> wrote:
>
> struct ccsr_ddr __iomem *ddr = (void *) CONFIG_FOO_ADDR;
> struct ccsr_ddr __iomem *ddr =
>         (struct ccsr_ddr __iomem *) CONFIG_FOO_ADDR;
>
> You have told me the second format is preferred. I have been using this
> format since. But in practice, the second format is often too long and I
> have to wrap to next line. It's not a problem for new code. As I am
> trying to cleanup the existing code, I would have to make more changes.
> So I am back to this question. Is the first format (using void *)
> accetable in long term?

I think you can blame me for the first version.  I started doing that
years ago exactly because the second version is too long.

I think the first version is preferred because the second version is
unnecessarily complex.  The reason you need to cast the macro to a
pointer is because it's defined as an integer, which is the real "bug"
here.  All of these macros should be defined as pointers, but that's a
huge change that causes problems elsewhere.  Since you're already
"cheating" by making them integers, you would just be pretending to do
the right thing by using the "proper" cast.  By using "(void *)",
you're saying that you are "fixing" the integer by making it into a
pointer.

I don't know if this makes any sense.


More information about the U-Boot mailing list