473,382 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Global Data declaration : "error: initializer element is not constant"

Hi All,

I need a tree data structure for my application. It is the non -
cyclic
simple tree where i can have any number of children node and each
child can recursively become a sub tree like a normal tree. Now the
thing is i can popullate my tree at compile time like a global data.
Since
i know my tree definition at compile time, instead of using pointers
to point to siblings or child nodes, i am planning to use the array
with undefined length like int a[] = {1,2}.
Issue is if i declare complete tree at one place like this, my code
become unreadable and unmanageable because of nested and high depth
of
tree. Even if i format code with 2 white space, it will become very
big with around 10-20 levels and 20 nodes at each level. Also
declaring each node with some logical name instead of an array
element
at some position will also make it easy to modify in future when
required.
I was planning to declare each node seperately and then use that in
tree as reference
like
Structure Node leaf1 = {1,1,1};
Structure Node leaf2 = {1,1,1};
Structure Node leaf3 = {1,1,1};
and then
Structure Node node[] = {1,1,1, leaf1, leaf2, leaf3};
But the problem is i can not reference a variable like this as global
data above my main method like this
#include <stdio.h>
Structure Node leaf1 = {1,1,1};
Structure Node leaf2 = {1,1,1};
Structure Node leaf3 = {1,1,1};
Structure Node node[] = {leaf1, leaf2, leaf3};
int main()
{
/// do processing;
return 0;

}
It gives compilation error "error: initializer element is not
constant". Pls let me know how can i handle such situation.

Regards
-

Oct 15 '07 #1
2 4978
On 15 Oct, 09:44, hankyp...@gmail.com wrote:
#include <stdio.h>

Structure Node leaf1 = {1,1,1};
Structure Node leaf2 = {1,1,1};
Structure Node leaf3 = {1,1,1};

Structure Node node[] = {leaf1, leaf2, leaf3};

int main()
{
/// do processing;
return 0;

}

It gives compilation error "error: initializer element is not
constant". Pls let me know how can i handle such situation.
That is not what it gives at all, unless you are using some hitherto
unknown language rather than C.

1. There is no "Structure" keyword in C.
2. Even if you meant "struct", the datatype "struct Node" is undefined
in your code.
3. Given the above, I'm not even going to try and determine what the
rest of the code means, if anything.

Oct 15 '07 #2
ha*******@gmail.com wrote:
>
.... snip ...
>
#include <stdio.h>

Structure Node leaf1 = {1,1,1};
Structure Node leaf2 = {1,1,1};
Structure Node leaf3 = {1,1,1};

Structure Node node[] = {leaf1, leaf2, leaf3};

int main() {
/// do processing;
return 0;
}

It gives compilation error "error: initializer element is not
constant". Pls let me know how can i handle such situation.
^^^ ^

Well, it isn't constant. It refers to variable objects.

Please avoid these confusing misspellings, as underlined above.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com

Oct 19 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: SenthilSS | last post by:
My application produces XML Data files which have XML namespace qualified XML elements (nodes), but the namespace itself is not declared in the data file. My task is to read these data files in a...
2
by: Todd Nathan | last post by:
Hi. have this code and compiler problem. GCC 2.95.3, BeOS, error "initializer element is not constant" #ifdef FILEIO { static struct { char *sfn; FILE *sfd; } stdfiles = {
3
by: Brian Foree | last post by:
I am developing an ASP.NET application that uses Access 2000 as its backend, and have just started getting the following error on 2 ASP.NET pages that had been working until late last week (and I...
10
by: PB | last post by:
Hi ! I have the following code, which I am using in an Embedded systems, c-compiler.. However I see the same problem with GCC too.. I need the last 10 bits of an address pointer, which is...
2
montzter
by: montzter | last post by:
Hi, Got some declarations below but when I compiled it I got the above mentioned error. 1. I'd like to know if my implementation or stucture is doable. 2. How could i fix the problem...?...
4
by: floppyzedolfin | last post by:
Hello! I'm actually encoding an encryption / decryption program. The encryption programes takes a file path in parameter, and encrypts the contents of the file and stores that into another file. ...
1
by: jan.geek | last post by:
Hi all, When reading the following ugly but valid (according to w3c XSV) xsd into a DataSet I get "Duplicated declaration PossiblesValue" error. Can anyone tell me why? This is a small part...
9
by: Rohit | last post by:
I am trying to initialize an array whose initializers depend on value of Enums. I take enum and then decide the initializer value, so that even if enum value changes because of addition to list...
3
by: zoeb | last post by:
Hi, I am declaring an array which carries x coordinates, however these will vary depending on the geometry the user enters. I have set my code up as follows, but get the "initializer element...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.