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 6166099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:16:52+00:00 2026-05-23T22:16:52+00:00

I am writing a program that will call a function from an external library,

  • 0

I am writing a program that will call a function from an external library, given a list of bitfield flags provided by the end user of my program. I was initially planning on maintaining a lookup table of all the possible flags, but the list of flags varies by platform and I don’t have complete documentation for the library. I had planned to use the c preprocessor to include only the defined flags for the current platform in the table, but this is turning out to be hard to maintain because I have to rely on users reporting missing flags for platforms to which I don’t have access.

I then thought I could allow the users to pass in the flag names as strings. But I can’t find a way to test if a macro is defined, given only the string name of the macro. So if a user wanted to set the flag FLAG_ABC, they’d pass in “FLAG_ABC” as an argument and I’d have to do some magic to check if &FLAG_ABC != NULL. Is this possible?

  • 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-05-23T22:16:53+00:00Added an answer on May 23, 2026 at 10:16 pm

    All #define‘s are lost after preprocessing. If you want to have the information of preprocessor-symbols available at run-time you have to have the names (and values of course) of these macros as strings in your executable OR as a separate file which you then fread at run-time. I could imagine it would be anoying to have two lists of flags, one with the #define-symbols and one with the strings and then manually caring that if you update the one you also update the other without error.

    I would go with the separate file you load at run-time but instead of having the updating-trouble just have that file be a header-file you also #include. Specifically what i suggest is: move all your flag-definition #define's into a separate header-file, include it in your sources so you can use it as you are used to, create a mini-parser reading in the file at run-time, i.e. parsing each line #define asdf 0xF1A6 into a string and an int. If this works in practice and you then want to prevent the user from accidentally changing that header-file you could either hash it or binary-encode it.

    The alternative with which you can have the #define-symbols as strings actually in your binary would be to generate a .rc-file from that header file (or both the header-file and the .rc from a .csv-file) and then using the resource-compiler to inline it in your binary’s .rsrc-section, you have to write the helper-program (which transforms the file) though and integrate a call to that transformer-program into your make-script or build-system to always have the .rc up-to-date.

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

Sidebar

Related Questions

I am writing an assembly function to be called from C that will call
I am writing a program that will draw a solid along the curve of
I have Virtual PC 2007. I am writing a C# program that will run
I am writing a program in Python that will act as a server and
If you are writing a program that is executable from the command line, you
I am writing a program that is meant to be extended by some function
I'm writing a program that passes data from a file into an array, but
I am writing a native function that will return multiple Python objects PyObject *V
I'm writing a program that sends an email out at a client's specific local
I'm writing a program that uses SetWindowRgn to make transparent holes in a window

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.