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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:36:01+00:00 2026-05-23T11:36:01+00:00

I have 2 versions of the same program with only little changes between the

  • 0

I have 2 versions of the same program with only little changes between the two. Instead of having separate files, I use #if defined (PAR) – #else – #endif and then compile with or without -cpp -DPAR to switch between the 2 versions. I like this way as you only have to work on a single hs file. However, since my aim is to write parallel/optimised version of the original program, I wonder if using #if-#else#-endif has any performance implication? Basically I would like an explanation of how this works under the hood. Thanks

#if defined(PAR)
import Control.Parallel
import Control.Parallel.Strategies
import Control.DeepSeq
#endif

#if defined(PAR)
test = sum ( map expensiveFunc myList `using` strat )
    where strat = parListChunk 100 rseq
#else 
test = sum ( map expensiveFunc myList )
#endif

Note:

Instead of the -cpp flag, you could use the language options in your source file:

e.g. {-# LANGUAGE CPP #-}

But you still need to provide (or not) -Dxxx when compiling in order to choose which part of the program the compiler should ignore ( where xxx is the defined variable in the hs file).

  • 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-23T11:36:02+00:00Added an answer on May 23, 2026 at 11:36 am

    C preprocessor directives are in effect only during compilation. The compiler simply cuts out the lines within the #ifdef block and then compiles the program as usual, so there is no runtime performance penalty.

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

Sidebar

Related Questions

I have two versions of a product and am using separate Hg repositories for
I have two files from a C program. I guess both belong to quite
I have 3 versions of the same assembly in the GAC (Global Assembly Cache),
Is it possible to have both versions of maven running on the same computer?
This is probably an easy question... I have 4 source versions of the same
We have two version of the same assembly in GAC? I want my client
We have two versions of a managed C++ assembly, one for x86 and one
I have two versions of rails (2.1.0 and 2.2.2) installed in my computer. When
We have two machines (under discussion) running ClearCase - different versions of ClearCase. Otherwise,
I have a perl script that prepares files for input to a binary program

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.