Tool News
 
 
 

Tool News

Products Info
Downloads
Tools FAQs
MAEC TOOL NEWS: MAECT-M3T-NC308WA_3-030316D

A Note on Using C Compilers
M3T-NC308WA, M3T-NC30WA, M3T-NC79WA
and M3T-NC77WA

Please take note of the following problem in using C compilers (with an assembler and integrated development environment) M3T-NC308WA, M3T-NC30WA, M3T-NC79WA, and M3T-NC77WA:
  • On the standard library function "sprintf"


  1. Products and Versions Concerned
    For the M32C/80 and M16C/80 series MCUs
    M3T-NC308WA V.1.00 Release 1 through V.5.00 Release 1
    For the M16C/60, M16C/30, M16C/20, and M16C/10 series MCUs
    M3T-NC30WA V.1.00 Release 1 through V.5.00 Release 2
    For the 79xx series MCUs
    M3T-NC79WA V.2.00 Release 1 through V.4.10 Release 1A
    For the 77xx series MCUs
    M3T-NC77WA V.3.00 Release 1 through V.5.20 Release 4

  2. Description
    If a space is inserted between two arguments, % and f, of the "sprintf" standard library function, the result of an assignment may become such a value as 0.000000. (The number of decimal places varies according to the specified format of the sprintf function.)

  3. Condition
    This problem occurs if a floating-point number explained below is assigned to argument "f".
    This floating-point number is such a value as 0.9999999, which can be rounded off to 1 as the nearest whole number.

  4. Example
    -----------------------------------------------------------------------
       #include <stdio.h>
    
       float   f;
    
       int     main( void )
       {
               char   buf[10];
    
               f = 0.9999999;
    
               sprintf( buf,"% f",f );  /*A space inserted between % and f*/
       }
    -----------------------------------------------------------------------
    In the above example, the value assigned to "buf" becomes 0.000000.

  5. Workaround
    This problem can be circumvented in either of the following ways:
    (1) Modify the source file "print.c" of the standard library function as follows and re-create the standard library file by using the librarian:

    Modification of "print.c":
    To the processing in the _f8prn function, add the four lines with the comment of "Processing to add" as shown in an example below.
    Notes:* This modification part begins at the 986th line in the M3T-NC308WA V.5.00 Release 1, and this beginning line varies according to compilers and their versions.
    * The English version does not have any comments in the comment columns.
    --------------------------------------------------------------------
       if ( CHK_KETA ) {
               if ( (p_flg == 'e' || p_flg == 'E') && inte[0]=='9' ) {
               /* %e              9       */
                       inte[0] = '1';         /*                  */
                       if ( CHK_EFUGO ) {
                               /*                        */
                               cnt--;
                               if ( !cnt )
                                       /*                              */
                                       CLR_EFUGO;
                       } else
                               cnt++;
               } else {
                       for ( r=0; r<seisu; r++ ) {
                               if ( inte[r] == '9' ) 
                                       inte[r] = '0';
                               else {
                                       ++inte[r];
                                       break;
                               }
                       }
                       if ( r==seisu && r!=0) {
                               inte[seisu] = '1';
                               seisu++;
                       }
                       else if( seisu == 0){      /* Processing to add */
                              inte[seisu] = '1';  /* Processing to add */
                              seisu++;            /* Processing to add */
                       }                          /* Processing to add */
               }
       }
    --------------------------------------------------------------------
    Re-create the standard library file by going through the following steps:
    1. Modify the print.c file saved in the SRCxx\lib directory under the directory where your product is installed. Here xx denotes the numerals in each product type.
    2. Re-create the standard library file using the makefile.dos file saved in the SRCxx\lib directory.
    3. Copy the re-created standard library file to the directory indicated by environment variable LIBxx.
    (2) Pass the absolute value of a floating-point number to the sprintf function as its argument.
    --------------------------------------------------------------------
       #include <stdio.h>
       #include <math.h>       /* math.h included */
    
    
       float   f;
    
       int     main( void )
       {
               char   buf[10];
    
               f = 0.9999999;
    
               /* The absolute value of a real number assigned 
                                     after the first line of the buffer */
               /* No space inserted after % */
    
               buf[0] = ' ';              /* A space assigned to buf[0] */
               sprintf( &buf[1],"%f",f ); /* The value of f assigned 
                                                       following buf[1] */
       }
    --------------------------------------------------------------------

  6. Schedule of Fixing the Problem
    We plan to fix this problem in our next release of the products.




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