Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7937101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:26:06+00:00 2026-06-03T22:26:06+00:00

I am trying to make a look up table. Here is the pretext: Suppose,

  • 0

I am trying to make a look up table. Here is the pretext:

Suppose, following is the defines list of certain macros.

#define ENTITY1 0x10001001
#define ENTITY2 0x10001002
.
.
.

The ENTITY_ is the User readable string value of the otherwise unsigned long integer type value and there can be any number of macros (say greater than 200, or even 500).

Now, there is a list which keeps track of which entity exists in which file number. Something like this:

 0x10001001 1
 0x10001002 2
 0x10001003 3
 .
 .
 .

The use of the long unsigned integers for each ENTITY is necessary because of proprietary conventions.

The first list is already present, and the second list needs to be generated through a program by using the macro strings in #defines of the first list as the user enters the record.
Since the number of such entries is very large, hard coding each value is a burdensome task. Also, if the first list is updated, the second list will not update appropriately if additional switch cases are not coded.

When the user makes an entry, he tells that the entry is to be made in ENTITY3 through a string variable, the system should look up if a macro exists by the name ENTITY3. If yes, then open the file with number 3 and do the necessary processing, otherwise, display warning that such an entry does not exist.

So, how do I compare the string variable entered by the user with a macro name without using SWITCH CASE?

I am using C programming. GNU C Library.


Edit: Here is the scenario.

The different entities named ENTITYn (n can be any number) can exist in different files which have a certain integer number 1,2,3…
But, the proprietary environment has built up these entities such that they are recognized using certain unsigned long integers like 0x01001001 etc. For each entity, the macros have been defined in some header files corresponding to those entities by the name ENTITY1 ENTITY2…
Now when a certain manager wants to change something, or enter certain data to a particular entity, he would address is by the name ENTITYn, and the program would look up in a lookup table for a corresponding entry. If a match is found, it would use the unsigned long integer code for that entity for subsequent processing internal to the proprietary system, access another lookup table which looks for which file number has this entry and opens that file location for processing.

I need to populate this second table with the unsigned long ints of the Entities and their corresponding locations (let all of them be in a single file 1 for now). I want to circumvent the condition, that the one making that LUT has to know the corresponding entity unsigned long integer codes. The program uses the input string i.e. ENTITY1 and directly maps it.

But now I am beginning to think that hardcoding a LUT would be a better option. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:26:08+00:00Added an answer on June 3, 2026 at 10:26 pm

    Macros are preprocessor features, they’re not visible to the C compiler. So you cannot directly reference the “values” of macros from code.

    It seem you need two look-up tables, if I get this correctly:

    1. One table mapping a string such as ENTITY1 to to a unique unsigned integer, such as 0x10001001.
    2. One table mapping an unsigned integer such as 0x10001001 to a “file number” which looks like a (small) unsigned integer such as 1.

    Both of these tables can be generated by processing the source code you seem to have. I would recommend gathering the ENTITYn strings into something like this:

    struct entity_info
    {
      const char *name;
      unsigned int key;
    };
    

    Then have your pre-processing code build a sorted array of these:

    const struct entity_info entities[] = {
    { "ENTITY1", 0x10001001 },
    { "ENTITY2", 0x10001002 },
    /* and so on */
    };
    

    Now you can implement an efficient function like this:

    unsigned int get_entity_key(const char *entity_name);
    

    It could perhaps use binary-search, internally.

    Then you need to do the second step, obviously. I’m not sure of the exact details of these values (how and when they can change); if the “file number” for a given entity is constant, it could of course be added directly into the entity_info structure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make something look like following (don't concern color here. my
I'm trying to make a UITableView look as though it's on top of a
Hello guys look to my code I'm trying to make a program which asks
I am trying to make a simple application that turns a character to look
I'm trying to make a table view with an appearance much like the default
I am trying to make my layout look like so. I have tried gridviews,
I'm trying to make an html table that looks like this: 1 2 3
I am trying to make a Dictionary lookup table in C#. I need to
Alright now i am trying to make a cool looking table with using CSS
I'm trying to make a dynamic table with knockout js and I'm having a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.