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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:23:37+00:00 2026-06-12T03:23:37+00:00

I am using Preprocessor Directives to define function macros in C. Can I have

  • 0

I am using Preprocessor Directives to define function macros in C. Can I have multiple if/else if statements in a function macro?

If yes how do I write it?

#define WRITE(str,id) #str(id)

// HERES where I am having difficulty
#define DRAW_GENERIC_WINDOW(windowID, type) if type==1 WRITE(draw_text,windowID) else if type==2 WRITE(draw_image,windowID) else if type==3 WRITE(draw_hyperlink,windowID)

// usage
DRAW_GENERIC_WINDOW(112, 1);
DRAW_GENERIC_WINDOW(178, 2);
DRAW_GENERIC_WINDOW(988, 3);

// At compile time the above should be converted to...
draw_text(112);
draw_image(178);
draw_hyperlink(988);

I am aware how to perform a single if else statement in a Function Macro but not how to do it with multiple if/else if’s:

// if else eg
#define DRAW_GENERIC_WINDOW(windowID, type) ((type)==(1))?WRITE(draw_text,windowID):WRITE(draw_image,windowID)

Note: Before you ask “Why the hell are you programming like this?” 😛 its because I am writting in a language that is very similar to C called 4dm, except there are no structs, pointers or the ability to declare new data types. So I am forced to resort to Preprocessor Directives in order to achieve some form of virtual functions(used when I dont know the type of window – image, hyperlink, etc. – that I am working with).

  • 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-12T03:23:38+00:00Added an answer on June 12, 2026 at 3:23 am

    Try it out like this:

    #define WRITE(str,id) str(id)
    
    // HERES where I am having difficulty
    #define DRAW_GENERIC_WINDOW(windowID, type) if (type==1) \
    WRITE(draw_text,windowID) \
    else if (type==2) \
    WRITE(draw_image,windowID) \
    else if (type==3) \
    WRITE(draw_hyperlink,windowID)
    
    // usage
    DRAW_GENERIC_WINDOW(112, 1);
    DRAW_GENERIC_WINDOW(178, 2);
    DRAW_GENERIC_WINDOW(988, 3);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With using plain C preprocessor macros, is it possible to create something like: INIT_BASE(0x100)
In my jmeter test, I have a BSF PreProcessor step (using groovy) running before
In C Programming, We can enable/disable loop optimization using #pragma preprocessor directive. In which
Using C++ preprocessor directives, is it possible to test if a preprocessor symbol has
While using this line of code, I get the error CS1040: Preprocessor directives must
I read that Objective-C was made by using preprocessor directives to add features of
I want to comment a line using the pre-processor: #define open /##* #define close
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using Location.getBearing(); I seem to get randomly changing bearings. Aka, I can turn the
Background I've been using the C preprocessor to manage and compile semi-large javascript projects

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.