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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:19:05+00:00 2026-05-12T17:19:05+00:00

Is the C preprocessor able to perform integer arithmetic? E.g.: #define PI 3.1416 #define

  • 0

Is the C preprocessor able to perform integer arithmetic?

E.g.:

#define PI 3.1416
#define OP PI/100
#define OP2 PI%100

Is there a way OP and/or OP2 get calculated in the preprocessing phase?

  • 1 1 Answer
  • 1 View
  • 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-12T17:19:05+00:00Added an answer on May 12, 2026 at 5:19 pm

    Integer arithmetic? Run the following program to find out:

    #include "stdio.h"
    int main() {
        #if 1 + 1 == 2
            printf("1+1==2\n");
        #endif
        #if 1 + 1 == 3
            printf("1+1==3\n");
        #endif
    }
    

    The answer is "yes". There is a way to make the preprocessor perform integer arithmetic, which is to use it in a preprocessor condition.

    Note however that your examples are not integer arithmetic. I just checked, and GCC’s preprocessor fails if you try to make it do float comparisons. I haven’t checked whether the standard ever allows floating point arithmetic in the preprocessor.

    Regular macro expansion does not evaluate integer expressions. It leaves it to the compiler, as can be seen by preprocessing (-E in GCC) the following:

    #define ONEPLUSONE (1 + 1)
    #if ONEPLUSONE == 2
       int i = ONEPLUSONE;
    #endif
    

    The result is int i = (1 + 1); (plus probably some stuff to indicate source file names and line numbers and such).

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

Sidebar

Related Questions

Is there a way to get the C/C++ preprocessor or a template or such
Is there a way to (ab)use the C preprocessor to emulate namespaces in C
Is there a way to do the following preprocessor directives in Python? #if DEBUG
I have the following preprocessor divective: #ifndef NDEBUG #define TRACE printf #else #define TRACE(...)
Are there any preprocessor symbols which allow something like #if CLR_AT_LEAST_3.5 // use ReaderWriterLockSlim
I'm looking for a way to convert a preprocessor token to a string. Specifically,
If I write a #define that performs an operation using other preprocessor constants, is
I found this regarding how the C preprocessor should handle string literal concatenation (phase
I would like to be able to do something like #print C Preprocessor got
I was wondering if there is some standardized way of getting type sizes in

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.