Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | BartC <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Sum using variadic macros |
| Date | 2016-12-14 20:06 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <o2s8la$utf$1@dont-email.me> (permalink) |
| References | (1 earlier) <871sxa919h.fsf@bsb.me.uk> <o2rfjg$vi$1@dont-email.me> <e2a70b5a-462d-4510-b994-b2dd4a77c46a@googlegroups.com> <o2s5vd$k2d$1@dont-email.me> <5e39ec50-7c87-4d76-8979-981f0ebdbbf6@googlegroups.com> |
On 14/12/2016 19:26, Thiago Adams wrote: > On Wednesday, December 14, 2016 at 5:20:39 PM UTC-2, Bart wrote: >> Why can't you calculate it at runtime during initialisation? Or does it >> have to be used in array bound or switch-case expressions? > > > Yes, I want to use in switch-case. > Otherwise I would use some function address to work as a "ID". > > I suspect, I didn't check, that switch-cases are faster then if-elses because the compiler can create some table. Yes, if the values are localised. But good hash values would be spread out and over a wide range making the use of a jump table harder. If the strings are small however, say 4 characters or less, I might just use the character codes directly: 'this'. Although you'd have to check what different compilers do with multi-character literals like this. Presumably you are looking up a hashed string against a set of pre-calculated hash values. I think you might be better off with an actual hash table, if the switch statement can't use the hash values profitably. -- Bartc
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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