helpgperf - Support: sr #108399, gperf should also generate a macro...

 
 

sr #108399: gperf should also generate a macro to calculate the hash value

Submitted by:  None
Submitted on:  Wed Sep 25 09:27:14 2013  
 
Category: NonePriority: 5 - Normal
Severity: 1 - WishStatus: Wont Do
Privacy: PublicAssigned to: Bruno Haible <haible>
Originator Email: -unavailable-Open/Closed: Closed
Operating System: None

Add a New Comment (Rich MarkupRich Markup):
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Sun Nov 27 17:50:45 2016, comment #1:

It is an interesting idea.

Unfortunately, you cannot do much string processing in C. The only string operation you have in the C preprocessor is the concatenation.

You could try to work on a list of characters, i.e. lookup3('f', 'o', 'o') instead of lookup("foo"), but this soon gets very ugly.

So, the best approach I can see is that at build time you generate a file with preprocessor defines such as
#define INDEX_OF_foo 5
#define INDEX_OF_bar 2
etc.
and have a macro
#define index_of(arg) INDEX_OF_ ## arg

Bruno Haible <haible>
Project AdministratorIn charge of this item.
Wed Sep 25 09:27:14 2013, original submission:

background: I use gperf for embedded development to maintain a key-value database in flash for a fixed set of variables. When I get a string from the outside world I use the 'lookup' function. A subset of the variables are never exposed to the outside world, counters, statistics and are manipulated internally. For these variables it would be very convenient to have a macro which would calculate the hash value of the known string (lookup("foo")): this would give me the index at compile time, which could be used to give (1) a compile time guarantee that I only try to look up existing strings and (2) would avoid the runtime overhead of calculating the hash for known strings.

(1) would be a pleasant property, (2) would be extremely useful to avoid the runtime overhead for a code base with hundreds of internal variables.

If there are no takers, I will probably end up doing this, in which case I'll be glad to submit a patch if there is interest.

Thanks, Laszlo Nemeth

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by haible (Posted a comment)
  • -unavailable- added by None (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sun Nov 27 17:50:45 2016haibleStatusNone=>Wont Do
      Assigned toNone=>haible
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup