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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:44:37+00:00 2026-05-29T05:44:37+00:00

Clearly, there are times where #define statements must have parentheses, like so: #define WIDTH

  • 0

Clearly, there are times where #define statements must have parentheses, like so:

#define WIDTH 80+20

int a = WIDTH * 2; // expect a==200 but a==120

So I always parenthesize, even when it’s just a single number:

#define WIDTH (100)

Someone new to C asked me why I do this, so I tried to find an edge case where the absence of parentheses on a single number #define causes issues, but I can’t think of one.

Does such a case exist?

  • 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-29T05:44:38+00:00Added an answer on May 29, 2026 at 5:44 am

    Yes. The preprocessor concatenation operator (##) will cause issues, for example:

    #define _add_penguin(a) penguin ## a
    #define add_penguin(a) _add_penguin(a)
    
    #define WIDTH (100)
    #define HEIGHT 200    
    
    add_penguin(HEIGHT) // expands to penguin200
    add_penguin(WIDTH)  // error, cannot concatenate penguin and (100) 
    

    Same for stringization (#). Clearly this is a corner case and probably doesn’t matter considering how WIDTH will presumably be used. Still, it is something to keep in mind about the preprocessor.

    (The reason why adding the second penguin fails is a subtle detail of the preprocessing rules in C99 – iirc it fails because concatenating to two non-placeholder preprocessing tokens must always result in a single preprocessing token – but this is irrelevant, even if the concatenation was allowed it would still give a different result than the unbracketed #define!).

    All other responses are correct only insofar that it doesn’t matter from the point of view of the C++ scanner because, indeed, a number is atomic. However, to my reading of the question there is no sign that only cases with no further preprocessor expansion should be considered, so the other responses are, even though I totally agree with the advice contained therein, wrong.

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

Sidebar

Related Questions

There are times when a programmer clearly has made a deliberate choice in their
I'd like to define a trait with some properties which have a well defined
Suppose you are calling a function, where there's clearly a need to break down
This is clearly not appears like it wouldn't be a best practice. Can someone
I hope I can explain this clearly enough. I have my main form (A)
So there are two constraints to my question: I must use an external function
I've been bitten a couple of times by statements in VB.NET (not sure if
The following example is clearly fictional but it resumes how validation is done on
I have a program that needs to run a function M times per iteration,
I have a windows form and user select cloth parameters from comboboxes like country-state-city

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.