Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12605 Discussions

initializer element is not a constant

Altera_Forum
Honored Contributor II
1,145 Views

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
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
402 Views

 

--- 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.
0 Kudos
Altera_Forum
Honored Contributor II
402 Views

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 };
0 Kudos
Reply