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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:52:37+00:00 2026-05-13T22:52:37+00:00

I was looking for a tool that can convert C code expressions for the

  • 0

I was looking for a tool that can convert C code expressions for the form:

a = (A) ? B : C;

into the ‘default’ syntax with if/else statements:

if (A)
  a = B
else
  a = C

Does someone know a tool that’s capable to do such a transformation?

I work with GCC 4.4.2 and create a preprocessed file with -E but do not want such structures in it.

Edit:
Following code should be transformed, too:

a = ((A) ? B : C)->b;
  • 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-13T22:52:38+00:00Added an answer on May 13, 2026 at 10:52 pm

    Coccinelle can do this quite easily.

    Coccinelle is a program matching and
    transformation engine which provides
    the language SmPL (Semantic Patch
    Language) for specifying desired
    matches and transformations in C code.
    Coccinelle was initially targeted
    towards performing collateral
    evolutions in Linux. Such evolutions
    comprise the changes that are needed
    in client code in response to
    evolutions in library APIs, and may
    include modifications such as renaming
    a function, adding a function argument
    whose value is somehow
    context-dependent, and reorganizing a
    data structure. Beyond collateral
    evolutions, Coccinelle is successfully
    used (by us and others) for finding
    and fixing bugs in systems code.

    EDIT:
    An example of semantic patch:

    @@ expression E; constant C; @@
    (
      !E & !C
    |
    - !E & C
    + !(E & C)
    )
    

    From the documentation:

    The pattern !x&y. An expression of this form is almost always meaningless, because it combines a boolean operator with a bit operator. In particular, if the rightmost bit of y is 0, the result will always be 0. This semantic patch focuses on the case where y is a constant.

    You have a good set of examples here.

    The mailing list is really active and helpful.

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

Sidebar

Related Questions

I am looking for a tool that can serialize and/or transform SQL Result Sets
I'm looking for a tool that can be installed on our monitoring server and
I'm looking for a tool that can map the relationships in my database in
I am looking for a (preferably) command-line tool that can reformat the C# source
I am looking for a tool like ltrace or strace that can trace locally
I'm looking for a tool that will reverse engineer Java into a sequence diagram
Looking for a tool that will automatically create a graphical representation of a MySQL
I'm looking for a tool that will be able to build a parser (in
I'm looking for a tool that will, in bulk, add a license header to
I'm looking for a tool that will generate an assembly/project dependency diagram in Visio

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.