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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:40:57+00:00 2026-06-01T20:40:57+00:00

I am stuck with the following problem: I have the two following correct working

  • 0

I am stuck with the following problem:

I have the two following correct working macros (expanding to Fortran90 code):

#define ld_dx(A)   (  (A(ixp1)-A(ix  ))/(dx)  )
#define rd_dx(A)   (  (A(ix  )-A(ixm1))/(dx)  )

(Note: these macros depend on the following additional macros:

#define ix    2:nx-1
#define ixp1  1+ix+1
#define ixm1 -1+ix-1

And they depend also the declarations:

integer, parameter :: nx = 100, dx = 1

)

In my code I can use these macros by a call as for example

X = X + ld_dx(Y)

or:

X = X + rd_dx(Y)

Now I would like to be able to call ld_dx(A) by writing d_dx(A,l) instead and rd_dx(A) by writing d_dx(A,r). The example would therefore look like this:

X = X + d_dx(Y,l)

or

X = X + d_dx(Y,r)

=> I am looking for a CPP macro that can provide this syntactic sugar (to get as close as possible to the mathematical notation). <=

The most straightforward thing to do would be:

#define d_dx(A,s)  s ## d_dx(A)

Unfortunately this does not work. CPP transforms

d_dx(Y,l)

into:

l ## Y)

I tried many things by studying the other CPP concatenation related questions, but I could not figure it out. Thank you very much in advance for some help!

Sam

PS: Note it would also be fine for me to rename the macros ‘ld_dx(A)’ and ‘rd_dx(A)’ into ‘dl_dx(A)’ and ‘dr_dx(A)’
This regarding, the most straightforward thing to do would be:

#define d_dx(A,s)  d ## s ## _dx(A)

Unfortunately this does not work neither: CPP transforms

d_dx(Y,l)

into:

d ## l ## _dx(Y) 
  1

Error: Expected a right parenthesis in expression at (1)

I.e. the concatenation is simply not performed.

  • 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-01T20:40:58+00:00Added an answer on June 1, 2026 at 8:40 pm
    #define PASTE(x,y) x##y
    #define d_dx(A,s) PASTE(s,d_dx)(A)
    

    Token pasting (## operator) and stringizing (# operator) suppress substitution of adjoining arguments, so you have to do it in two steps.

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

Sidebar

Related Questions

I am little bit stuck with the following problem. I have two models: class
I'm new to wicket and stuck with the following problem: I have a table
I'm a beginner programmer and I'm stuck with the following problem: If I have
I am stuck in a problem with an application. I have following lines of
I am new to Symfony2 and stuck at the following problem. I have an
I am new to Grails and currently stuck at the following problem: I have
I'm stuck with the following scenario and appreciate any help/advice.. Requirement I have number
I`m new to sql and have been stuck on the following issue for almost
This problem is giving me a real headache. I have two tables in my
I have the following arrangement : Tomcat --EJB-invokation--> JBoss (6.0.14) (5.1.0) The two servers

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.