Tool News
 
 
 

Tool News

Products Info
Downloads
Tools FAQs
RENESAS TOOL NEWS on March 1, 2004: RSO-M3T-NC308WA_1-040301D

A Note on Using C Compilers
M3T-NC308WA and M3T-NC30WA
--On Testing Equality/Inequality Between a Variable and a Constant--

Please take note of the following problem in using C compilers (with an assembler and integrated development environment) M3T-NC308WA and M3T-NC30WA
  • On testing equality/inequality between a variable of type signed or unsigned char and a constant


  1. Products and Versions Concerned
    M3T-NC308WA V.5.00 Release 1 and V.5.10 Release 1
         for the M32C/80 and M16C/80 series MCUs
    M3T-NC30WA V.5.00 Release 1 through V.5.10 Release 1
         for the M16C/60, M16C/30, M16C/Tiny, M16C/20, M16C/10, and R8C/Tiny series MCUs


  2. Description
    Testing equality/inequality between a variable of type signed or unsigned char and a constant may generate incorrect code.

    2.1  Conditions
    This problem occurs if the following five conditions are satisfied:
    (1) In an if statement exist two or more controlling expressions testing equality/inequality between a variable of type signed or unsigned char and a constant.
    (2) The variables in (1) are such as arrays or aggregates (whose elements are arranged continuously in memory space).
    (3) Operators used in the controlling expressions in (1) are all "==" or "!=".
    (4) The controlling expressions in (1) are associated with each other by a logical OR operator.
    (5) The following compile options are used:
    a. Any of those, -O1, -O2, -O3, -OR, and -OS, and -Ocompare_byte_to_word (-OCBTW), or
    b. O4 only, or
    c. O5 only

    2.2  Example
    -------------------------------------------------------------------
    char    c[2];                         /* Condition (2) */
    
    int     func( void )
    {
            if( c[0] == 1 || c[1] == 1 )  /* Conditions (1), (2), (3), 
                                                              and (4) */
                    return 0;
            else
                    return 1;
    }
    -------------------------------------------------------------------

  3. Workaround
    This problem can be circumvented in any of the following ways:
    (1) Split the if statement.
    -----------------------------------------
    char    c[2];
    
    int     func( void )
    {
            if( c[0] == 1 )        /* One of split if statement */
                    return 0;
            else if( c[1] == 1 )   /* The other of split if statement */
                    return 0;
            else
                    return 1;
    }
    -----------------------------------------
    (2) Don't use -Ocompare_byte_to_word (-OCBTW) together with any of the options -O1, -O2, -O3, -OR, and -OS.
    (3) Use -O3 instead of -O4 or -O5.


  4. Schedule of Fixing the Problem
    In the M3T-NC308WA, we plan to fix this problem in its next release.
    In the M3T-NC30WA, this problem has been resolved in its V.5.20 Release 1, so please upgrade your product to it.





© 2008. Renesas Technology Corp., All rights reserved. Privacy | Legal