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>