Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
Use name of #define parameter without stringification

Is there a way to get the exact words passed into the #define without stringifying? Example use case:

#define NUM 1

#define CREATE_FUN(X) \
void prefix_X() { \ // used exact words passed in
    int x = X; \ // use value later on
}

CREATE_FUN(NUM)

And output would look like:

void prefix_NUM() {
    int x = 1;
}
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Use the token concatenation (##):

#define NUM 1

#define CREATE_FUN(X) \
void prefix_##X() { \
    int x = X; \
}

CREATE_FUN(NUM)
over 4 years ago · Santiago Trujillo Report

0

#define CREATE_FUN(X) \
int prefix_##X() { \
    int x = X; \
    return x; \
}

CREATE_FUN(NUM)
over 4 years ago · Santiago Trujillo Report

0

You can use Token Pasting(##) operator:

#define CREATE_FUN(X) int prefix_##X() { int x=X; return x;}

Sample use case:

Some compilers provide an extension that allows ## to appear after a comma and before __VA_ARGS__, in which case

  1. the ## does nothing when VA_ARGS is non-empty

  2. removes the comma when VA_ARGS is empty.

This makes it possible to define macros with variable number of arguments such as fprintf (stderr, format, ##__VA_ARGS__)

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!