Re: [gtk-list] Re: Q: (gtk-entry) convert integer/float to char/string



Erik Mouw wrote:
> > void
> > set_gentry( GtkWidget *entry, gchar *fmt, ... )
> > {
> >         va_list ap;
> >         gchar *str;
> >
> >         if( !entry )
> >                 return;
> >
> >         if( !fmt )
> >                 fmt = "";
> 
> Your function is OK, but IMHO you should change these five lines in:
> 
>   g_assert(entry != NULL);
>   g_assert(fmt != NULL);
> 
> Passing a NULL pointer is a programmer's error, so the programmer should
> know immediately that there is a mistake in his program. If you do it your
> way, you don't know what went wrong, and you even don't know that it went
> wrong at all. With an assertion it is quite clear: the programmer made a
> mistake, and in this particular case the mistake was passing a NULL
> pointer, please check your code.

This was actually deliberate, my app can run in a command-line mode (so
testing for widget==NULL is part of turning off updates when there's no
display), and I like set_gentry( item, NULL ) to mean "clear the entry".

But you're right, of course, sanity checking is important for any
library stuff.

John
--
John Cupitt, john.cupitt@ng-london.org.uk, +44 (0)171 747 2570
VASARI Lab, The National Gallery, Trafalgar Square, London, WC2N 5DN



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