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

  • Home
  • SEARCH
  • 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 6804525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:28:36+00:00 2026-05-26T19:28:36+00:00

I never use the comma operator. But sometimes, when I write some recursions, I

  • 0

I never use the comma operator.
But sometimes, when I write some recursions, I make a stupid mistake: I forget the function name. That’s why the last operand is returned, not the result of a recursion call.

Simplified example:

int binpow(int a,int b){
    if(!b)
        return 1;
    if(b&1)
        return a*binpow(a,b-1);
    return (a*a,b/2); // comma operator
}

Is it possible get a compilation error instead of incorrect, hard to debug code?

  • 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-26T19:28:36+00:00Added an answer on May 26, 2026 at 7:28 pm

    Yes, with a caveat. The gcc has the -Wunused-value warning (or error with -Werror). This will take effect for your example since a*a has no effect. Compiler result:

    test.cpp: In function ‘int binpow(int, int)’:
    test.cpp:6:43: warning: left operand of comma operator has no effect [-Wunused-value]
    

    However, this won’t catch single-argument calls and calls where all arguments have side effects (like ++). For example, if your last line looked like

    return (a *= a, b/2);
    

    the warning would not be triggered, because the first part of the comma statement has the effect of changing a. While this is diagnoseable for a compiler (assignment of a local, non-volatile variable that is not used later) and would probably be optimized away, there is no gcc warning against it.

    For reference, the full -Wunused-value entry of the manual with Mike Seymours quote highlighted:

    Warn whenever a statement computes a result that is explicitly not used. To suppress this warning cast the unused expression to void. This includes an expression-statement or the left-hand side of a comma expression that contains no side effects. For example, an expression such as x[i,j] will cause a warning, while x[(void)i,j] will not.

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

Sidebar

Related Questions

i never use sql server ROW_NUMBER() function. so i read some article regarding ROW_NUMBER(),PARTITION
I know to never use built-in function names as variable identifiers. But are there
How do I make vi - Vim never use tabs (converting spaces to tabs,
I've been using user controls extensively but never use a HttpHandler and was wondering
So I've tried to work with the pure-CSS, never-use-tables-for-layout gospel, I really have. But
I am keeping a reference to the example object but I never use retain
I have been told to never use == for strings but for everything else
I use ON DELETE CASCADE regularly but I never use ON UPDATE CASCADE as
I seldom use inheritance, but when I do, I never use protected attributes because
I'm trying to send emails but the emails will never use my :from =>

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.