Nullstone Logo

COMPANY
Home
Contacts
Customers
Testimonials

PRODUCTS
Overview
NULLSTONE for C
NULLSTONE for Java
Technical Overview

SUPPORT
Release Notes
Download
PGP Information
Service Report
Write Us

INFORMATION
Performance Results
Glossary of Terms

RELATED LINKS
Compiler Connection
Compiler Jobs

Previous Up Next
If Optimization

The conditional expression of an IF statement is known to be true in the then-clause and false in the else-clause, and this information can be used to simplify nested IF and other statements. In addition, two adjacent IF statements with the same conditional expressions can be combined into one IF statement.

Example:

In the code fragment below, the conditional-clause of the nested IF statement can be eliminated.

    void f (int *p)
    {
      if (p)
        {
          g(1);
          if (p) g(2);
          g(3);
        }
      return;
    }
    

Below is the code fragment after the nested conditional-clause has been eliminated.

    void f (int *p)
    {
      if (p)
        {
          g(1);
          g(2);
          g(3);
        }
      return;
    }
    

Example:

In the code fragment below, the two IF statements can be combined into one IF statement.

    void f (int *p)
    {
      if (p) g(1);
      if (p) g(2);
      return;
    }
    

Below is the code fragment after the two IF statements have been combined into one IF statement.

    void f (int *p)
    {
      if (p)
        {
          g(1);
          g(2);
        }
      return;
    }
    

© 1990-2012 Nullstone Corporation. All Rights Reserved.