Re: [gtk-list] offtopic colons and gtk (;



On Thu, 26 Aug 1999, Andreas Leitner wrote:

> Hi,
> 
> I know that question is slightly off topic, but it would be nice if you
> would not flame me for this, or even better give me an answer (:
> 
> I have found some colons (':') in the source code of GTK for which I
> don't know what exactly they are therefore. For example GtkEditable is
> defined as follows:
> --
> struct _GtkEditable
> {
>   GtkWidget widget;
> 
>   /*< public >*/
>   guint      current_pos;
> 
>   guint      selection_start_pos;
>   guint      selection_end_pos;
>   guint      has_selection : 1;
> 
>   /*< private >*/
>   guint      editable : 1;
>   guint      visible : 1;
>   GdkIC     *ic;
>   GdkICAttr *ic_attr;
>   
>   gchar *clipboard_text;
> };
> 
> --
> What do the ": 1" after `editable', `visible' and 'has_selection' mean?
> I know this is a C question, but I have never seen such a construct
> before. Any help is greatly apprechiated.

these are bitfields, e.g. a bitfield of size 2 you can only store 4
values (0-3), and :1 just means this is a flag.
compilers usually pack multiple bitfields, so:

struct _foo
{
  guint x : 1;
  guint y : 2;
  guint z : 5;
  guint f : 24;
};

usually only takes up 4 bytes.
bitfields are only valid within structures though.
  

> 
> many thanks in advance,
> Andeas
> 

---
ciaoTJ



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