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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:42:45+00:00 2026-05-29T04:42:45+00:00

Is it possible to concatenate string from another macro when #including a file name

  • 0

Is it possible to concatenate string from another macro when #including a file name (in C). For example,

I have,

#define AA 10 
#define BB 20

these are parameters that change with program runs

And the file include:

#include "file_10_20" // this changes correspondingly i.e. file_AA_BB

Is it possible to have something like #include "file_AA_BB" somehow? I googled to find that double pound operator can concat strings but couldn’t find a way of doing it.

Any help would be appreciated.

  • 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-29T04:42:46+00:00Added an answer on May 29, 2026 at 4:42 am

    First I thought “that’s easy”, but it did take a few tries to figure out:

    #define AA 10 
    #define BB 20
    
    #define stringify(x) #x
    #define FILE2(a, b) stringify(file_ ## a ## _ ## b)
    #define FILE(a, b) FILE2(a, b)
    
    #include FILE(AA, BB)
    

    As requested I’ll try to explain. FILE(AA, BB) expands to FILE2(AA, BB) but then AA and BB is expanded before FILE2, so the next expansion is FILE2(10, 20) which expands to stringify(file_10_20) which becomes the string.

    If you skip FILE2 you’ll end up with stringify(file_AA_BB) which won’t work. The C standard actually spends several pages defining how macro expansion is done. In my experience the best way to think is “if there wasn’t enough expansion, add another layer of define“

    Only stringily will not work because the # is applied before AA is replaced by 10. That’s how you usually want it actually, e.g.:

    #define debugint(x) warnx(#x " = %d", x)
    debugint(AA);
    

    will print

    AA = 10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Ienumerable<string> collection that I want to concatenate into a single string with
Possible Duplicate: How to concatenate strings of a string field in a PostgreSQL ‘group
Possible Duplicate: How do I concatenate strings in Objective-C? I have two strings and
I have a 'black box' application that gets a map of values as parameters,
Is possible to concatenate a String already existing in strings.xml with the current one.
I have a List of List<String> 's which I get from a external API
Possible Duplicate: C String Concatenation How do I concatenate multiple char strings in C
Possible Duplicate: C++ concatenate string and int Hi, In C# I can write like
Possible Duplicate: How to concatenate two arrays in Java? I have SET1 declared as
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have

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.