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



Daniel

Thanks for reply.  You seem to know your stuff.
If pointers are more complicated and unnecessary sometimes,
then why does GTK+ have so many pointers? 
Why are many things of GtkWidget* type and not GtkWidget?

It seems like GdkColor is the first widget I found that
is not declared to be a pointer in sample code I found.

If this structures elements were *not* integers than then
suggested initialization "= {0, 0, 0, 0}" would not work right?
I'd have to replace those 4 zeroes with whatever type the struc
held right?

Thanks,

Chris

On Mon, Apr 22, 2002 at 09:36:29PM +0200, Daniel Elstner wrote:
> Am Mon, 2002-04-22 um 21.22 schrieb rsteinke w-link net:
> > From: Christian Seberino <seberino spawar navy mil>
> > >
> > > 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???
> 
> Since when is everything else a pointer?  Don't use pointers if you
> don't have to.
> 
> > > 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;
> 
> You're confusing something.  A class can be created on stack, as well as
> allocated in free storage / heap. 
> 
> > This'll get you a nice seg fault.
> > 
> > You're declaring a pointer, but not allocating any memory.
> 
> Yes.  And there's no reason to make your life harder just for the sake
> of having a pointer.
> 
> > > 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. :(
> 
> Forget that rubbish.  There's no 'extern "C" struct'.  extern "C" does
> nothing but specify the C linkage convention for functions -- don't
> worry if you don't understand this yet.
> 
> > Go look at any basic C language reference (not C++).
> 
> Any good C++ book will help you as well.  C++ is mostly compatible to C,
> except for some obscure features that are deprecated in C too.  If it
> weren't compatible, you wouldn't even be able to include GTK+ headers in
> your program.
> 
> --Daniel

-- 
=======================================================
| 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]