Re: GtkArg typesafety
- From: David Benson <daveb idealab com>
- To: George <jirka 5z com>
- cc: gnome-devel-list gnome org, recipient list not shown: ;
- Subject: Re: GtkArg typesafety
- Date: Tue, 4 Jan 2000 17:45:55 -0800 (PST)
For that amount of typing you could say:
GtkArg arg = {0};
arg.type = GTK_TYPE_INT;
arg.name = "blah"
GTK_VALUE_INT(arg) = 42;
gtk_object_setv(object, 1, &arg);
And *this* mess could be generically wadded into a macro.
(Although I'm not sure this is recommended otherwise since GtkArg
might theoretically change...)
I do agree with you fundametally btw: it is annoying that you
cannot change a double => int or vice versa
at the object level w/o hand-checking
for all instances of set_arg and similar ilk.
- Dave
On Tue, 4 Jan 2000, George wrote:
> On Tue, Jan 04, 2000 at 12:02:05PM -0500, Havoc Pennington wrote:
> > IMO this is much extra complexity for very little gain (it avoids the
> > "0" is not a double problem, but that's all really; it doesn't solve
> > the problem of passing entirely the wrong type or getting const-ness
> > wrong). And it ruins the nice syntax which is 85% of the point of
> > arguments.
>
> Ok, added full type safety, so with this, using args is just as type safe as a
> normal function call.
>
> #ifdef __GNUC__
> #define MY_PERSON_ARG_NAME(arg) "name",({char *z = (arg); z;})
> #define MY_PERSON_GET_ARG_NAME(arg) "name",({char **z = (arg); z;})
> #define MY_PERSON_ARG_DOB(arg) "dob",({glong z = (arg); z;})
> #define MY_PERSON_GET_ARG_DOB(arg) "dob",({glong *z = (arg); z;})
> #define MY_PERSON_ARG_DOD(arg) "dod",({glong z = (arg); z;})
> #define MY_PERSON_GET_ARG_DOD(arg) "dod",({glong *z = (arg); z;})
> #else /* __GNUC__ */
> #define MY_PERSON_ARG_NAME(arg) "name",(char *)(arg)
> #define MY_PERSON_GET_ARG_NAME(arg) "name",(char **)(arg)
> #define MY_PERSON_ARG_DOB(arg) "dob",(glong )(arg)
> #define MY_PERSON_GET_ARG_DOB(arg) "dob",(glong *)(arg)
> #define MY_PERSON_ARG_DOD(arg) "dod",(glong )(arg)
> #define MY_PERSON_GET_ARG_DOD(arg) "dod",(glong *)(arg)
> #endif /* __GNUC__ */
>
> This not only casts, but gives a warning even on wrong pointer types. I'm
> really starting to like GNU C extentions.
>
> George
>
>
> --
> To unsubscribe: mail gnome-devel-list-request@gnome.org with "unsubscribe"
> as the Subject.
>
>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]