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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:48:52+00:00 2026-06-05T08:48:52+00:00

In gcc, I can write foo ? : bar which is a shorthand form

  • 0

In gcc, I can write foo ? : bar which is a shorthand form of foo ? foo : bar but I see that K&R doesn’t mention it.

Is this something I should rely on, defined in some standard? Or just an (evil) gcc extension I should avoid?

  • 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-05T08:48:54+00:00Added an answer on June 5, 2026 at 8:48 am

    This is a GCC extension by the name:
    Conditionals with Omitted Operands.

    It is not standard c.Using -pedantic flag for compilation will tell you so.

    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.

    Is this something I should rely on, defined in some standard? Or just an (evil) gcc extension I should avoid?

    Depends on your requirements, If your code does’nt need to run on any other compiler implementation other than GCC then you can use it. However, if your code is to build on across different other compiler implementations then you should not use it.

    Anyhow, One should aim to write as much intuitive and readable code as possible given that I would always suggest avoiding such (ugly)constructs.

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

Sidebar

Related Questions

This is annoying, i can write a function with these parameters/return, but why cant
Has anyone taken advantage of the automatic vectorization that gcc can do? In the
In gcc I can do compile-time warnings like this: #if !defined(_SOME_FEATURE_) #warning _SOME_FEATURE_ not
What windows C IDE can I use that will use gcc to compile and
Actually I have read about that I can write Objective-C app on Linux (using
How to write this assembly code as inline assembly? Compiler: gcc(i586-elf-gcc). The GAS syntax
I'm using gcc for my c programmes. How can I check which method is
I just realised that this program compiles and runs (gcc version 4.4.5 / Ubuntu):
I am trying to write a thread safe logger class so that i can
As far as I know, in gcc you can write something like: #define DBGPRINT(fmt...)

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.