Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C Moderated > Initializing a ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 1030 of 1099
Post > Topic >>

Initializing a Tree at compile Time: "error: initializer element is not constant"

by hankypan1@[EMAIL PROTECTED] Jan 12, 2008 at 04:46 PM

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
-
-- 
comp.lang.c.moderated - moderation address: clcm@[EMAIL PROTECTED]
 -- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line.  Sorry.




 3 Posts in Topic:
Initializing a Tree at compile Time: "error: initializer element
hankypan1@[EMAIL PROTECTE  2008-01-12 16:46:35 
Re: Initializing a Tree at compile Time: "error: initializer ele
t3chn0n3rd <darrin_all  2008-02-17 12:04:56 
Re: Initializing a Tree at compile Time: "error: initializer ele
hnarkaytis@[EMAIL PROTECT  2008-03-08 12:21:22 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue May 13 14:44:59 CDT 2008.