Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Global Data declaration : "error: initializer element is not constant"

Reply
Thread Tools

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

 
 
hankypan1@gmail.com
Guest
Posts: n/a
 
      10-15-2007
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
-

 
Reply With Quote
 
 
 
 
keith@bytebrothers.co.uk
Guest
Posts: n/a
 
      10-15-2007
On 15 Oct, 09:44, (E-Mail Removed) 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.

 
Reply With Quote
 
 
 
 
CBFalconer
Guest
Posts: n/a
 
      10-15-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) 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

 
Reply With Quote
 
Wade Ward
Guest
Posts: n/a
 
      10-21-2007


"CBFalconer" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> (E-Mail Removed) 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.

You end with l big endian though. Yet in German, the reading order is
different
again: 42 is pronounced zwei und vierzig, big endian writing, little endian
reading (for 2 digits only

It depands on how well you love your dictionary. zwo un fertig.
--
wade ward
(E-Mail Removed)
"Der Katze tritt die Treppe hoch; Der Kater tritt sie krumm.%
% De Teufel geit um; er bringt de menschen allet dumm."
schau, schau


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"initializer element is not constant" emin.martinian@gmail.com Python 1 05-30-2006 10:15 PM
initializer element is not constant Scott C Programming 15 01-24-2005 04:33 AM
Initializer element not computable at load time Clint Olsen C Programming 6 10-18-2003 10:00 AM
build error on Linux - initializer element is not computable at load time B. Wood C Programming 7 10-17-2003 06:14 PM
Error: "initializer element is not constant" Todd Nathan C Programming 2 07-30-2003 04:29 PM



Advertisments