Re: GdkColor weird type? Why not pointer like GtkWidget*....



rstein

Thanks so much for this reply! I was really confused
about this!  Can I ask you a follow up question?

Just to make GdkColor be like everything else (a pointer)
is it OK to try declaring all colors to be pointer (GdkColor*) types???

Then instead of:
      Colors::myStaticColor.red = 343;

I could hopefully do:
      (*Colors::myStaticColor).red = 343;

or even better, Colors::myStaticColor->red = 343; 

Hopefully I can then initialize things to make them look more like a class:

       GdkColor* Colors::myStaticColor = (GdkColor*) 0;



Is there any reason this fantasy should not work??? I tried last nite
and got seg faults so I don't know if this is not doable or I just
made a dumb mistake.  As you said, GdkColor is a "extern C struc".  I'm not
a "extern C struc" expert. :(

Sincerely,

Chris

On Mon, Apr 22, 2002 at 10:53:35AM -0700, rsteinke w-link net wrote:
> > From: Christian Seberino <seberino spawar navy mil>
> >
> > I've seen examples in GTK+ books where GdkColor widgets
> > are not declared to be pointers   (GdkColor* myColor;)
> > but instead declared like this... (GdkColor  myColor;)
> >
> > I don't know if this begins to explain g++ not liking
> > this initialization or not....
> >
> > GdkColor Color:myStaticColor = (GdkColor 0); // *won't work!!*
> >
> > *only* this works...
> >
> > GdkColor Color:myStaticColor = {0}; // *won't work!!*
> >
> > Is GdkColor some weird type or something?? Do you
> > know why {0} works but not "(GdkColor) 0"???
> 
> (GdkColor) 0 doesn't work because it's not a pointer.
> 
> It really an extern "C" struct with four members.
> Since it's extern "C", you need to initialize it
> in the proper C (_not_ C++) way. For a struct in C,
> you provide an initialization list for the members,
> e.g.
> 
> GdkColor color = {0, 0, 0, 0};
> 
> If you provide fewer initializers than there are members,
> the last initializer is used to initialize all remaining
> members, so
> 
> GdkColor color = {0};
> 
> is equivalent.
> 
> Just because you're initializing GdkColor in C++ doesn't
> mean you can treat it like a C++ class. It's still a
> C struct.
> 
> Ron Steinke

-- 
=======================================================
| Dr. Christian Seberino  || (619) 553-7940  (office) |
| SPAWARSYSCEN 2363       || (619) 553-2836  (fax)    |
| 53560 HULL ST           ||                          |
| SAN DIEGO CA 92152-5001 || seberino spawar navy mil |
=======================================================



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]