Re: GtkSpinButton Patch



Thus spake David Wheeler:
> On May 2,  4:23pm, Nils Barth wrote:
> > Subject: Re: GtkSpinButton Patch
> 
> >>>
> >>>Side note: kernel-traffic's latest issue had a note on a possible
> >>>problem with a simple MAX a la GLib, namely that it evaluates
> >>>functions twice, which can be bad for some functions (say, if they
> >>>return different values on repeated calls). Someone suggested
> >>>replacing it with a dummy variable assignment, then
> >>>comparing/assigning with those variables. This might also be a bit
> >>>faster...
> >>>The exact code was (for MIN):
> >>>#define min(x, y) ({typeof (x) x_ = (x); \
> >>>                    typeof (y) y_ = (y); \
> >>>                    x_ < y_ ? x_ : y_;})
> 
> Problem is, "typeof" is a GNU gcc extension.
> That's not a problem for the Linux kernel; they _specifically_
> require GNU gcc, and are even very picky about compiler versions.
> 
> If you want GTK+ to run compile using compilers other than gcc,
> you'll have to avoid "typeof".

Oops... Okay, this would be a very bad reason to break portability.
I was just afraid that naive use of MIN/MAX etc. could result in hard
to find bugs, as described above.
Maybe a note in the GLib reference that says:
Note that the MIN, MAX, ABS and CLAMP macros evaluate their arguments
(er, the returned argument) twice, so one should be careful passing
them functions as arguemnts

-- 
  -nils
Public key: http://www.fas.harvard.edu/~nbarth/pub-key.txt



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