Re: GdkColor weird type? Why not pointer like GtkWidget*....
- From: Daniel Elstner <daniel elstner gmx net>
- To: Christian Seberino <seberino spawar navy mil>
- Cc: rsteinke w-link net, gtk-list gnome org
- Subject: Re: GdkColor weird type? Why not pointer like GtkWidget*....
- Date: 23 Apr 2002 11:04:39 +0200
Am Mon, 2002-04-22 um 21.21 schrieb Christian Seberino:
> 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;
Just for the sake of completeness: If you really want to allocate a
GdkColor dynamically, you can do (in C++):
GdkColor* color = new GdkColor;
...
delete color; // delete it when you done with it
or, in both C and C++:
GdkColor* color = g_new(GdkColor, 1); /* or g_new0(GdkColor, 1) */
...
g_free(color);
g_new0() zero-initializes the allocated memory, too. However, this
isn't correct if the struct contains pointers -- at least it isn't
portable (though GTK+ seems to rely on it sometimes).
Note 1: This won't work in a static initializer, as you seem to use in
your example above. You'd have to initialize the pointer with 0 first,
and allocate the memory at runtime.
Note 2: Be careful not to mix delete and g_free().
Note 3: Don't bother with dynamic allocation if it isn't needed ;)
Cheers,
--Daniel
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]