Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Declaring struct as static is causing problem.

Reply
Thread Tools

Declaring struct as static is causing problem.

 
 
param
Guest
Posts: n/a
 
      01-13-2006
Declaring struct as static is creating problem with newer version of CC
compiler 5.7 in solaris.

e.g.

static struct new_str {
int a;
int b;
};

It shows the Error : "static" is not allowed here.

Pls help me out of this problem. Also what is the significance of
declaring type as static ....as is shown above for new type new_str.

Regards
Parminder

 
Reply With Quote
 
 
 
 
Daevaorn
Guest
Posts: n/a
 
      01-13-2006
struct new_str { //type cannot be static!
int a;
int b;
};

static new_str a; //declare a static variable

 
Reply With Quote
 
 
 
 
param
Guest
Posts: n/a
 
      01-13-2006
hi Daevaorn ,

That's true that type cannot be static. But this code was working fine
with earlier compiler
i.e. CC 4.2. I want to know what was the benefit of declaring "static
struct" at that time.

May be it was that :
1.) static was used so that it has global visiblity only in the
declaration file.
2.) or was it declared with the notion that declaring static struct
will force all the variables of this type to be initialized with
defailt values.

I don't know i am confused. what was the significance of declaring it
that way.

Regards
Parminder

 
Reply With Quote
 
Daevaorn
Guest
Posts: n/a
 
      01-13-2006
hmm...
May be this is the solve:

struct new_str {
int a;
int b;
} var; // that code works fine

 
Reply With Quote
 
Daevaorn
Guest
Posts: n/a
 
      01-13-2006
hmm...
May be this can solve problem:

struct new_str {
int a;
int b;
} var; // that code works fine

 
Reply With Quote
 
Jack Klein
Guest
Posts: n/a
 
      01-15-2006
On 13 Jan 2006 01:07:26 -0800, "param" <(E-Mail Removed)> wrote in
comp.lang.c++:

> hi Daevaorn ,
>
> That's true that type cannot be static. But this code was working fine
> with earlier compiler
> i.e. CC 4.2. I want to know what was the benefit of declaring "static
> struct" at that time.


There was no benefit, it's just that the compiler had a defect, so
someone wrote sloppy code that did not generate a diagnostic.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
 
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
Can *common* struct-members of 2 different struct-types, that are thesame for the first common members, be accessed via pointer cast to either struct-type? John Reye C Programming 28 05-08-2012 12:24 AM
static struct initialization in a Class:: -- not my struct christian.bongiorno@gmail.com C++ 2 09-20-2006 06:53 PM
Is declaring a pointer to an undefined struct legal? Chris Barts C Programming 8 01-17-2005 01:19 PM
struct my_struct *p = (struct my_struct *)malloc(sizeof(struct my_struct)); Chris Fogelklou C Programming 36 04-20-2004 08:27 AM
Issues with declaring struct arrays inside of a struct Richard Mathis ASP .Net Building Controls 0 10-10-2003 03:14 PM



Advertisments