Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

initializer element is not a constant

How can I get rid of the following error: initializer element is not a constant?

I use NIOS II IDE in the C programming language.

Before I had the code:

# define ip1 134# define ip2 35# define ip3 134# define ip4 112

.

.

.

const struct ip_settings eth_ip =

{

interfacetype, ((UINT32) ip4<<24 | ((UINT32) ip3 <<16) | ((UINT32)ip2<<8) |((UINT32) ip1 <<0))

}

---

Now I want to reload the values for ip1, ip2,ip3 and ip4 during operation.

So I put:

int ip1 = 134;

int ip2 = 35;

int ip3 = 134;

int ip4 = 112;

instead of the defines.

Compiling this leads to the error "initializer element is not a constant" http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/sad.gif How do I get around without this error message?

Thanks for your help in advance.

andy

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    originally posted by andy@Sep 6 2006, 03:18 PM

    how can i get rid of the following error: initializer element is not a constant?

    i use nios ii ide in the c programming language.

    before i had the code:

    # define ip1 134# define ip2 35# define ip3 134# define ip4 112

    .

    .

    .

    const struct ip_settings eth_ip =

    {

    interfacetype, ((uint32) ip4<<24 | ((uint32) ip3 <<16) | ((uint32)ip2<<8) |((uint32) ip1 <<0))

    }

    ---

    now i want to reload the values for ip1, ip2,ip3 and ip4 during operation.

    so i put:

    int ip1 = 134;

    int ip2 = 35;

    int ip3 = 134;

    int ip4 = 112;

    instead of the defines.

    compiling this leads to the error "initializer element is not a constant" http://forum.niosforum.com/work2/style_emoticons/<#emo_dir#>/sad.gif how do i get around without this error message?

    thanks for your help in advance.

    andy

    <div align='right'><{post_snapback}> (index.php?act=findpost&pid=18107)

    --- quote end ---

    --- Quote End ---

    look at the "const" before your variable inistialization.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I assume you are using C not C++? A quick test showed that it should work in a *.cpp file but not in a *.c file. If you really want to get rid of the defines you could use something like

    enum ip {
      ip1 = 134,
      ip2 = 35,
      ip3 = 134,
      ip4 = 112
    };