Re: Stupid design question: guint vs. gint



>>>>> "D" == Derek Simkowiak <dereks@kd-dev.com> writes:

 D> 	This is a quickie :).

 D> 	I'm creating a child class of the GtkEditable.  I'm trying to
 D> figure out if I should use gint or guint for some of the
 D> functions.  For example, GtkEditable has

 D> void gtk_editable_insert_text (GtkEditable       *editable,
 D>                                const gchar      *new_text,
 D>                                gint              new_text_length,
 D>                                gint             *position);

 D> 	...and I want to add (notice the guints):

 D> void gtk_editable_insert_text_with_style (GtkEditable       *editable,
 D>                                           const gchar      *new_text,
 D>                                           guint  new_text_length,
 D>                                           guint             *position,
 D>                                           GtkEtextStyle *style);

 D> 	I want to use guints (a) because it makes sense and (b)
 D> because one underlying data structure is my GdkBufferGap, whose
 D> API is designed around guints (for things like position and
 D> length).

 D> 	So which is better: maintaining convention with gints, or
 D> using the more correct (as I see it) guints?

It depends. (right, clear, and useless answer).

No seriously, I can see one reason to use signed integers rather than
unsigned, namely that you can use negative numbers for specifying
special cases.  For example you can use position -1 to mean the end of
the buffer so the user wont have to write 

 insert (ed, "foo", strlen ("foo"), get_size (ed));

but can write simply

 insert (ed, "foo", strlen ("foo"), -1);

Isn't something similar used for selection?  Where e.g. 'select
(ed,0,-1)' means select the entire buffer.

It's not strictly necessary with such special cases so I guess it is a
matter of taste.

        /mailund



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