Talk About Network

Google


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 > Re: Initializin...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 1030 of 1134
Post > Topic >>

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

by t3chn0n3rd <darrin_allen@[EMAIL PROTECTED] > Feb 17, 2008 at 12:04 PM

On Jan 12, 4:46=A0pm, hankyp...@[EMAIL PROTECTED]
 wrote:
> 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. =A0Now 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[] =3D {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 =A0reference
> like
> =A0Structure Node leaf1 =3D {1,1,1};
> =A0Structure Node leaf2 =3D {1,1,1};
> =A0Structure Node leaf3 =3D {1,1,1};
>
> and then
> =A0 =A0 Structure Node =A0node[] =A0=3D {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>
>
> =A0Structure Node leaf1 =3D {1,1,1};
> =A0Structure Node leaf2 =3D {1,1,1};
> =A0Structure Node leaf3 =3D {1,1,1};
>
> =A0 Structure Node =A0node[] =A0=3D {leaf1, leaf2, leaf3};
>
> int main()
> {
> =A0/// 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: c...@[EMAIL PROTECTED]
 -- you
must
> have an appropriate newsgroups line in your header for your mail to be
see=
n,
> or the newsgroup name in square brackets in the subject line. =A0Sorry.

That is an interesting problem.  I am going to look at it on my Redhat
C++ compiler
-- 
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 Fri Jul 25 15:51:35 CDT 2008.