I think you would still need to do a strcmp within each case to protect against collisions. Maybe a better approach would be to have a global string table along with string indices? Also, you might be able to use the offset of the string in memory somehow - after all, your compiler will have to store it somewhere. I'm just not sure what the syntax would be. Regards, - Marcel On Fri, Aug 1, 2008 at 3:53 PM, Mark Rages wrote: > On Fri, Aug 1, 2008 at 3:55 PM, Timothy Weber wrote: > > Mark Rages wrote: > >> Frequently when writing string parsing code I've wanted a simple > >> string hash algorithm that is implemented in the C preprocessor. > >> (and, perhaps, in C code as well). > > > > How would you access individual characters of a string in the > preprocessor? > > Here's how to access the first character: > > #define TEST(a) *a > > printf("Value of first character: %d\n",TEST("Hello")) > > I think any decent C compiler would do that at compile time. > > > > > Or are you talking about implementing this within a custom preprocessor? > > That would be easier, the preprocessor isn't designed for looping or > recursion. > > I was hoping someone had done this before, or considered it and > decided it was a bad idea and could tell me why. > > Regards, > Mark > markrages@gmail > -- > Mark Rages, Engineer > Midwest Telecine LLC > markrages@midwesttelecine.com > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist