bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] Add a new xsumn function to lib/xsize.h.


From: Bruno Haible
Subject: Re: [PATCH] Add a new xsumn function to lib/xsize.h.
Date: Thu, 22 Sep 2011 23:26:27 +0200
User-agent: KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; )

Hello Mansour,

> I have a small feature request for lib/xsize.h: a variadic function,
> xsumn, to safely sum any number of size_t type arguments. Similar to
> xsum3 and xsum4. Attached is a small patch.

Thanks for the suggestion, but I don't see a way to do this in a reliable
and efficient manner.

About reliability, I mean that when the programmer writes

   xsumn (3, a, b, c)

the compiler does not verify the number of arguments. If the programmer
was accidentally writing

   xsumn (3, a, b, c, d)
or
   xsumn (3, a, b)

there would be no warning. Just code that has bugs as runtime.

About efficiency, I mean, we want these computations to be nearly as fast
as normal additions. You put a 'static inline' in front of the function,
but it does not help. Functions with varargs cannot be inline (at least
with the current versions of GCC). To reproduce this, I compiled this file:

============================ foo.c =========================
#include <stdint.h>
#include "xsize.h"

size_t foo (size_t n1, size_t n2, size_t n3)
{
  return xsum3 (n1, n2, n3);
}

size_t bar (size_t n1, size_t n2, size_t n3)
{
  return xsumn (3, n1, n2, n3);
}
============================================================
$ gcc -O -S -m32 foo.c -Winline
foo.c: In function 'xsumn':
xsize.h:111:1: warning: function 'xsumn' can never be inlined because it uses 
variable argument lists
foo.c: In function 'bar':
xsize.h:111:1: warning: inlining failed in call to 'xsumn': function not 
inlinable
foo.c:11:3: warning: called from here

> Also, I'm curious if this file needs documentation? I could not find
> any in doc/.

The first place to look for documentation is in the .h file. Only few gnulib
modules have their documentation in .texi format in the doc/ directory.

If you find that the comments in that file xsize.h are not sufficient, please
feel free to provide a patch.

Bruno
-- 
In memoriam Martha Corey <http://en.wikipedia.org/wiki/Martha_Corey>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]