Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #99378

Re: Sum using variadic macros

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: Sum using variadic macros
Date 2016-12-14 19:40 +0000
Organization A noiseless patient Spider
Message-ID <877f72710p.fsf@bsb.me.uk> (permalink)
References <03e6722a-248a-46e2-b06d-d1e84e471463@googlegroups.com> <871sxa919h.fsf@bsb.me.uk> <139c05b9-299f-4b55-ba6a-8fd4308c7ce4@googlegroups.com> <87oa0e79yp.fsf@bsb.me.uk> <o2s1q1$4pv$1@dont-email.me>

Show all headers | View raw


David Brown <david.brown@hesbynett.no> writes:

> On 14/12/16 17:26, Ben Bacarisse wrote:
>> Thiago Adams <thiago.adams@gmail.com> writes:
<snip>
>>> HASH3(a, b, c)  ((a) << 5 << 5) + ((b) << 5)  + (c)
>>
>> If the order does not matter, this is reasonably simple:
>>
>> #define sum(...) sum2(__VA_ARGS__, 0, 0, 0, 0, 0, 0))
>> #define sum2(a, b, c, d, e, f, ...) \
>>      ((((((((((f << 5) + e) << 5) + d) << 5) + c) << 5) + b) << 5) + a)
>
> The trouble with this is that it is hopeless as a hash function if you
> need to go to more than 6 characters (assuming 32-bit integers).  Hash
> functions for strings are one of the few good uses of rotation
> instructions.

Sure, but I've no idea what the OP is using these for and it's not
impossible that the expression the OP gave works for the intended
purpose.

But in fact is was the "vararg shift" idea I wanted to show.  It's handy
to know.

-- 
Ben.

Back to comp.lang.c | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Sum using variadic macros Thiago Adams <thiago.adams@gmail.com> - 2016-12-14 02:54 -0800
  Re: Sum using variadic macros Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-14 11:51 +0000
    Re: Sum using variadic macros David Brown <david.brown@hesbynett.no> - 2016-12-14 13:58 +0100
      Re: Sum using variadic macros Richard Heathfield <rjh@cpax.org.uk> - 2016-12-14 14:01 +0000
      Re: Sum using variadic macros Thiago Adams <thiago.adams@gmail.com> - 2016-12-14 08:05 -0800
        Re: Sum using variadic macros BartC <bc@freeuk.com> - 2016-12-14 19:20 +0000
          Re: Sum using variadic macros Thiago Adams <thiago.adams@gmail.com> - 2016-12-14 11:26 -0800
            Re: Sum using variadic macros BartC <bc@freeuk.com> - 2016-12-14 20:06 +0000
    Re: Sum using variadic macros Thiago Adams <thiago.adams@gmail.com> - 2016-12-14 05:25 -0800
      Re: Sum using variadic macros mark.bluemel@gmail.com - 2016-12-14 08:10 -0800
        Re: Sum using variadic macros Thiago Adams <thiago.adams@gmail.com> - 2016-12-14 08:23 -0800
          Re: Sum using variadic macros Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-14 11:32 -0800
      Re: Sum using variadic macros Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-14 16:26 +0000
        Re: Sum using variadic macros David Brown <david.brown@hesbynett.no> - 2016-12-14 19:09 +0100
          Re: Sum using variadic macros supercat@casperkitty.com - 2016-12-14 11:33 -0800
          Re: Sum using variadic macros Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-14 19:40 +0000

csiph-web