473,768 Members | 9,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5000
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
10012
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 C# app for viewing purposes. I am using "XmlDocument" and "DataSet" for displaying the XML data in the Data grid. Problem: If I add the Namespace declaration to the data file itself (by manually opening the file and adding a new Root element...
2
19571
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
8835
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 don't think I made any changes to either page other than changing the user control that creates the header). Server Error in '/myApp' Application. ---------------------------------------------------------------------------- ----
10
21171
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 completly know at link time, but will be symbols at the compile time. I used the following code for this initalization.. uint32 data_ptr_mask = ((uint32) data) & 0x3ff;
2
4700
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...? Suggestions? Thanks. //code typedef struct SomeStructTag
4
6229
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. I'm using AES for it is quick, and RSA to encrypt AES, to transmit AES keys (it'll run on two separate computers). Please notice that - this is my first C# code :)
1
4025
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 of a large xsd reverse engineered from an existing xml output from an application so despite the structure being crap it can't be changed. Thanks,
9
11196
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 even then I should be able to get correct value for the array element. I need value and state to be present in a single byte thats why I use macros. Here is what my code look like: typedef enum
3
2254
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 not constant" issue. I had the code compiling earlier, but made the mistake of moving thing aorund without taking a backup and now nothing works! Any help would be greatly appreciated. /*=======================================================*/...
0
9576
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10176
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10018
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9963
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9844
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8840
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6656
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5425
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2808
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.