[U-Boot] [PATCH v2 13/22] omap4: add clock support

Wolfgang Denk
2011-06-21T08:20:48Z

Dear Aneesh,

In message <4E00447B.9070804@ti.com> you wrote:
>
> $ gcc main.c
> main.c:5: error: initializer element is not constant
> main.c:5: error: (near initialization for ?arr[0]?)
> main.c:7: error: initializer element is not constant
> main.c:7: error: (near initialization for ?arr[1]?)

I have to admit that I don't understand either why this error is
raised here; after all, from our understanding of the code these _are_
constant addresses.

You may want to ask this in a compiler group...

> As a result, I will have to do something like this to populate my
> array:
>
> static unsigned int *const reg_arr[] = {
> &(((struct my_regs_struct *const)OMAP4_PRCM_REG_BASE)->uart_clkctrl),
> &(((struct my_regs_struct *const)OMAP4_PRCM_REG_BASE)->i2c_clkctrl),
> };
>
> Is this acceptable?

No, please don't.

Note that the following code compiles fine:

----------------------------- snip -----------------------------
#include <stdio.h>

struct my_regs_struct {
unsigned int reg1;
unsigned int reg2;
unsigned int reg3;
};

static struct my_regs_struct *const my_regs = (struct my_regs_struct *) 0x1000;

static void print_regs(void)
{
unsigned int *const reg_arr[] = {
&my_regs->reg1,
&my_regs->reg3,
};
printf("regs %p %p \n", (void *)reg_arr[0], (void *)reg_arr[1]);
}

int main(void)
{
print_regs();
return 0;
}
----------------------------- snip -----------------------------

With "gcc -Wall -pedantic" you will get warnings "initializer element
is not computable at load time [enabled by default]", but this can be
avoided by adding "--std=c99" to the compiler options.

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
"Wish not to seem, but to be, the best." - Aeschylus