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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:49:21+00:00 2026-05-18T06:49:21+00:00

Disclaimer: I am not a C programmer. I have recently seen a friend’s project.

  • 0

Disclaimer: I am not a C programmer.

I have recently seen a friend’s project. Due to reasons I don’t understand, he writes code in a string which is compiled at runtime. This results in something like:

char x[] = "int y = 5; printf(\"%i\", y)";
run_this_code(x);

Which is horrible to use because Visual Studio doesn’t step in and do syntax highlighting etc.

Using some preprocessor abuse, it is possible to do trick Visual Studio into thinking you’re writing real code and then having the preprocessor turn it into a string before the compiler gets hold of your source. This works:

#define STRINGIFY(x) #x

int main(void){
        char[] y = STRINGIFY(
                int x = 5;
                printf("%i", x);
        );
        printf("%s", y);
}

The problem with this is it prints out:

int x = 5; printf("%i\n", x);

The problem then is the runtime compiler says Error on line 1. Is there a way of making it include the newlines?

Update This is not my problem. It is someone else’s code, I just became interested in the idea of using the preprocessor to make his life easier. I have no idea why he’s doing it like this.

Update removed all mention of CUDA because this question is about the preprocessor, not CUDA.

  • 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-18T06:49:22+00:00Added an answer on May 18, 2026 at 6:49 am

    I first suggested that just escaping the newlines should be enough. Having had time to verify (and seeing the comment by the question’s owner), I realize that doesn’t cut it.

    I did some testing, and explicitly putting in newline symbols seems to work:

    char[] y = STRINGIFY(
                    int x = 5;\n
                    printf("%i", x);\n
            );
    

    I have only tested this on Linux though, not in a syntax-aware IDE. It’s possible that those “bare-looking” newlines will instead get flagged as syntax errors, by a clever syntax highlighter.

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

Sidebar

Related Questions

Disclaimer: I'm not a programmer, never was, never learned algorithms, CS, etc. Just have
DISCLAIMER: The following code is not something I would ever use in a real
(DISCLAIMER: I'm not a programmer, I spend my time on serverfault, I'm just a
Disclaimer: I have not used RoR, and I have not generated tests. But, I
Disclaimer, I'm not a PHP programmer, so you might find this question trivial. That's
Disclaimer This is not strictly a programming question, but most programmers soon or later
Disclaimer: This is not actually a programming question, but I feel the audience on
Disclaimer: This is for a homework assignment, but the question is not regarding the
Full disclaimer: I'm a CS student, and this question is related to a recently
Disclaimer: please do not bother reading this long post unless you are an embedded

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.