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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:09:52+00:00 2026-06-19T03:09:52+00:00

I am experimenting with preprocessor function-like macros so I am trying to write a

  • 0

I am experimenting with preprocessor function-like macros so I am trying to write a macro that forward declares regular functions. But when I go to compile it says that line 2 has incorrect syntax.

What am I doing wrong?

#define FORWARD_DECLARE_CUSTOM_FUNCT(fName) "int" #fName "(int id, string msg, string cmd);"
FORWARD_DECLARE_CUSTOM_FUNCT("abc") // LINE 2: Should become "int abc(int id, string msg, string cmd);"

void test()
{
    abc(1, "", "");
}
  • 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-19T03:09:54+00:00Added an answer on June 19, 2026 at 3:09 am

    The problem is all of the quotation marks.

    #define FORWARD_DECLARE_CUSTOM_FUNCT(fName) "int" #fName "(int id, string msg, string cmd);"
    

    translates to (after concatenating the string literals):

    "int abc (int id, string msg, string cmd);"
    

    Whereas,

    #define FORWARD_DECLARE_CUSTOM_FUNCT(fName) int #fName (int id, string msg, string cmd);
    

    translates to:

    int "abc" (int id, string msg, string cmd);
    

    What you really need is simply:

    #define FORWARD_DECLARE_CUSTOM_FUNCT(fName) int fName (int id, string msg, string cmd);
    

    Use it like this:

    FORWARD_DECLARE_CUSTOM_FUNCT(abc)
    

    It’s all just text replacement. I would personally remove the semicolon in the macro and make the user put one in after each use as well, to make it more like a statement. It feels more natural to me.

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

Sidebar

Related Questions

I recently started experimenting with Python decorators (and higher-order functions) because it looked like
Experimenting with jQuery and trying to make a small slide show that rotates through
I experimenting with jQuery. As I was trying I found out that I can't
Experimenting with Scala... I'm trying to define something analogous to the @ hack in
When experimenting with (embedded) Apache Derby DB, I noticed that a fresh database, with
I was experimenting with shell functions the other day, with the objective of overriding
I am experimenting with Dart. I have created an on click event like so:
I'm experimenting with Spring Mobile but I can't seem to get the basic example
Experimenting with Spring-JDBC. I am using this as reference. I am trying to get
Im experimenting with the espn public API and am trying to use their json

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.