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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:20:47+00:00 2026-06-17T05:20:47+00:00

This is how symbol concatenation is done in C . #define conc(a,b) a ##

  • 0

This is how symbol concatenation is done in C.

#define conc(a,b) a ## b

eg:

conc(hello,World) will make the symbol helloWorld.

What I need to know is a bit different. Say there’s a variable n that hold some integer. Now I need to create a symbol by concatenating another symbol with the value of n.

Eg:

n = 2
I need to define some function(...) so that function(symbol,n) will give symbol1 (not symboln) and when n = 3, function(symbol,n) will give symbol3 etc…

How can I define something like that?


This is what i really want to achieve. First, this is to be used to in AtmelStudio to program an atmega micro-controller. There are 4 USART modules there so are seperate set of registers, which change there names only by the number of the module.

For example, the four baud rate registers in four modules are UBRR0L, UBRR1L, UBRR2L, UBRR3L. (and there are several more, see below).

enter image description here

I need to write a function to initialize a given module by setting up values of the relevant registers. Since the register names vary only by the module number, if I can define some pre-processor directive as asked in this post, I can write a single function representing register names by some symbols, so the symbols will be bear relevant register names and the thing will go fine..

Eg:

If i can define conc(a,b) to do what I need, a simple function

void init(int no){
    conc(UBRR,no) = 0xF0;
}

Will be able to use to represent all the followings;

UBRR0 = 0xF0;
UBRR1 = 0xF0;
UBRR2 = 0xF0;
UBRR3 = 0xF0;

If this is not achievable, only thing I know is to re-write four separate functions. But hope there will be better alternatives..

  • 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-17T05:20:49+00:00Added an answer on June 17, 2026 at 5:20 am

    Preprocessor will operate on your code, BEFORE compilation & obviously much before run time. So no preprocessor directive can solve your purpose.

    The closest match would be to use a switch case as below:

    switch(n){
    case 0: ptr=&symbol0; break;
    case 1: ptr=&symbol1; break;
    case 2: ptr=&symbol2; break;
    case 3: ptr=&symbol3; break;
    case 4: ptr=&symbol4; break;
    case 5: ptr=&symbol5; break;
    //etc... needs to be filled manually.
    }
    

    & then operate on *ptr…

    Also if your variable names are going to be sequential, why not have an array, with name as symbol & symbol0 changed to symbol[0] ?

    EDIT:
    Saw the edit in the question now.
    You can have switch case as shown above, or create an array of pointers, which will hold UBRR0L, UBRR0L etc. & then use it with index. As much as I know, they are just registers & will be present at fixed addresses.

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

Sidebar

Related Questions

in know i need to locate this symbol in library.. I am trying to
I would know what this symbol should mean ?
Possible Duplicate: Reference - What does this symbol mean in PHP? I don't know
i have symbol type movie clip with name xmovie how to make this symbol
How id this symbol done? » I have the right facing version of it.
I have this value form database 10:00|10:15|10:30 and I need to replace this symbol
x = hello world.to_sym puts x.class This works and allows me to concatenate the
This symbol seems to be a compiler generated destructor. What is the difference between
Why is Android sending this symbol?(�) What I'm doing is, get a few variables,
What does this symbol mean in my Visual Studio IDE? Not the green bar,

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.