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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:38:22+00:00 2026-05-26T01:38:22+00:00

I’m trying to do something similar to another question , namely, conditionally include OpenMP

  • 0

I’m trying to do something similar to another question, namely, conditionally include OpenMP pragmas in my program. However, I want to go one step further and avoid that the user needs to specify omp every time they use the pragma. In other words, I want the following code to compile:

#include <cstdio>
#include <omp.h>

#ifdef _OPENMP
#   define LIB_PRAGMA_OMP(x) _Pragma("omp " #x)
#else
#   define LIB_PRAGMA_OMP(x)
#endif

int main() {
    LIB_PRAGMA_OMP(parallel) {
        std::printf("Hello from thread %d\n", omp_get_thread_num());
    }
}

Unfortunately, this doesn’t work. The compiler complains:

error: _Pragma takes a parenthesized string literal

If I use the following form, it works, though:

#define LIB_PRAGMA_OMP(x) _Pragma(#x)

…

LIB_PRAGMA_OMP(omp parallel) …

However, I’d really like to avoid this redundancy. How can I paste the (stringified) tokens correctly inside the _Pragma operator?

  • 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-26T01:38:23+00:00Added an answer on May 26, 2026 at 1:38 am

    After much trial and error, it turns out that the simplest solution works:

    #ifdef _OPENMP
    #   define LIB_PRAGMA_OMP(x)  DO_PRAGMA(omp x)
    #   define DO_PRAGMA(x) _Pragma ( #x )
    #else
    #   define LIB_PRAGMA_OMP(x)
    #endif
    

    With -DOPENMP, I get:

    # 12 "test_op.cpp"
    #pragma omp parallel
    # 12 "test_op.cpp"
    

    And without it, nothing.

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

Sidebar

Related Questions

Im trying to make something similar to twitpic.com's email submission feature. Their address schema
I am trying to recreate something similar to the popup keyboard used in safari.
I'm trying to implement something similar to what http://www.ancestry.com has, but I'm not sure
I'm trying to write something similar to this (sorry if the sample is not
I'm trying to build something similar to Facebook's privacy selection menu, except without the
Well,I am trying to do something similar what I did in Adobe Flex.Consuming a
This is what I'm trying to do something similar to the following request, but
I am a beginning javascript programmer. I am trying to create something similar to
I'm trying to write something very similar to an IM client (for learning purposes
I'm trying to insert a comment character into a string something similar to this:

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.