Re: [gtk-list] Re: Q: (gtk-entry) convert integer/float to char/string
- From: Erik Mouw <J A K Mouw its tudelft nl>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Re: Q: (gtk-entry) convert integer/float to char/string
- Date: Thu, 6 Apr 2000 20:05:24 +0200 (MET DST)
On Thu, 06 Apr 2000 14:10:26 +0100, John Cupitt wrote:
> Daniel Hops wrote:
>> in my gtk app I have to calculate digits (integers/floats) and want to
>> insert them in entries via "gtk_entry_set_text ()".
>> But this method only accepts chars. How can I easily make a function
>> like itoa? Or is there another way?
>
> Hi, I use something like this:
>
> /* Set a GtkEntry.
> */
> 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.
It's OK to silently ignore user errors.
Erik
--
Yes, it works sometimes. If you need something that "works sometimes"
use Windows! -- Victor Khimenko on linux-kernel
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]