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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:50:34+00:00 2026-06-05T09:50:34+00:00

Consider the following C program (ignore the double side-effect issue): #define max(a, b) (a>b?a:b)

  • 0

Consider the following C program (ignore the double side-effect issue):

#define max(a, b) (a>b?a:b)

int main(void){
    int max = max(5,6);
    return max;
}

The GCC preprocessor turns this into:

int main(void){
    int max = (5>6?5:6);
    return max;
}

Which is quite nice, since you don’t have to worry about unintentional collisions between max and max(). The GCC manual says:

A function-like macro is only expanded if its name appears with a pair of parentheses after it. If you write just the name, it is left alone

Is this standardized or just something done by convention?

  • 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-06-05T09:50:35+00:00Added an answer on June 5, 2026 at 9:50 am

    Yes, the behavior here is well-defined.

    Your macro max is a function-like macro (i.e., when you define it, its name is followed immediately by a left parenthesis and it takes arguments).

    A use of max later in your code is only an invocation of that macro if the use of max is followed by a left parenthesis. So, these would not invoke the max macro:

    int max;
    max = 42;
    

    But these would all invoke the max macro:

    max(1, 2)
    max (1, 2)
    max
    (
        1, 2
    )
    max()
    

    (Note that the last line is ill-formed because the number of arguments does not match the number of parameters. This is still a macro invocation, though, and would cause a compilation error.)

    This behavior is mandated by the C langauge standard. C99 §6.10.3/10 states that after a function-like macro has been defined,

    Each subsequent instance of the function-like macro name followed by a ( as the next preprocessing token introduces the sequence of preprocessing tokens that is replaced by the replacement list in the definition (an invocation of the macro).

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

Sidebar

Related Questions

Consider following program: static void Main (string[] args) { int i; uint ui; i
Consider the following C program: int main(void) { char string[10] __attribute__ ((aligned(32))); int i;
Consider the following C program, 'pause.c': void main() { pause(); } Compiling this on
Consider the following code: class Program { static void Main(string[] args) { try {
Lets us consider the following program : #include <stdlib.h> int main(int argc, char **argv){
Consider the following code: class Program { void Foo<T>() { } static void Main(string[]
Consider the following program. #include <stdio.h> int main() { int a[10]={0}; printf(%p %p\n, a,
Consider the following program, which is obviously buggy: #include <cstdio> double test(int n) {
Consider the following sample program in which a loop is running; int main() {
Consider the following code: #include <stdio.h> int main (void) { char str1[128], str2[128], str3[128];

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.