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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:45:32+00:00 2026-05-14T20:45:32+00:00

In the Android open-source qemu code I ran across this line of code: machine->max_cpus

  • 0

In the Android open-source qemu code I ran across this line of code:

machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */

Is this just a confusing way of saying:

if (machine->max_cpus) {
   ; //do nothing
} else {
 machine->max_cpus = 1;
}

If so, wouldn’t it be clearer as:

if (machine->max_cpus == 0) machine->max_cpus = 1;

Interestingly, this compiles and works fine with gcc, but doesn’t compile on http://www.comeaucomputing.com/tryitout/ .

  • 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-14T20:45:32+00:00Added an answer on May 14, 2026 at 8:45 pm

    This is permitted in GNU as an obscure extension to C

    5.7 Conditionals with Omitted Operands

    The middle operand in a conditional
    expression may be omitted. Then if the
    first operand is nonzero, its value is
    the value of the conditional
    expression.

    Therefore, the expression

     x ? : y
    

    has the value of x if that is nonzero;
    otherwise, the value of y.

    This example is perfectly equivalent
    to

     x ? x : y
    

    In this simple case, the ability to
    omit the middle operand is not
    especially useful. When it becomes
    useful is when the first operand does,
    or may (if it is a macro argument),
    contain a side effect. Then repeating
    the operand in the middle would
    perform the side effect twice.
    Omitting the middle operand uses the
    value already computed without the
    undesirable effects of recomputing it.

    As you can probably guess, avoiding this is recommended for readability and portability reasons. I’m honestly surprised to see such a grammar-incompatible extension to C.

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

Sidebar

Related Questions

Where can I browse the source code for any Android Open Source Project (AOSP)
My open-source Android application uses this in an SQL query: String.format(%f, someDoubleValue); Unfortunately, in
I cloned some of the trees from the Android Open Source Project to take
I know that the android plattform is open source. What I am interested in
Trying to build Android open source project on Ubuntu 10.04 (on VMware Player). I
Are the Android APIs open source? If so, I want to see how they
I have an open-source application on the Android market. It seems to work fine
I know that Google does some open source but a lot of their assets
From this article: Android Market could be invoked by an ACTION_VIEW intent with URI
In an Android app I developed, I open a cursor to a query with

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.