Tool News
 
 
 

Tool News

Products Info
Downloads
Tools FAQs
MESC TOOL NEWS: MESCT-NC308WA_2-001216D

NC308WA Precaution

Please take note of the following problems in using C compiler NC308WA (with an assembler and integrated development environment) for the M16C/80 series MCUs:
  • On pointers pointing to functions
  • On using a structure as an actual argument to a function with varying numbers of arguments


  1. Problem on Pointers Pointing to Functions
    1.1 Versions Concerned
    NC308WA V.1.00 Release 1 -- V.3.10 Release 1
    1.2 Description
    When a pointer to a function is assigned to a register variable and the address of the function is assigned to a variable of the pointer, only the lower 16 bits of the address are set to the variable.
    1.3 Conditions
    This problem occurs if the following three conditions are satisfied:
    (1) A pointer to a function is declared to be a register variable.
    (2) The address of the function is assigned to the pointer in (1) or used for initializing it.
    (3) Option "-fenable_register(-fER)" is used at compilation.

    In NC308WA V.3.10 Release 1, furthermore, this problem also arises if the following three conditions are satisfied:
    (1) A pointer to a function is declared to be an auto variable or register variable.
    (2) The address of the function is assigned to the pointer in (1) or used for initializing it.
    (3) Any one or more of the options -O, -O[1-5], -OR, and -OS are used at compilation.
    [Example]
          ------------------------------------------------------------------
          int func(void);
    
          int main(void)
          {
              register int (*p)(void) = func; /* The address of the function 
                                                         becomes incorrect */
              int i;
    
              i = p();     /* Not the function "func" but an incorrect address
                                                      is called indirectly */
              return i;
          }
          ------------------------------------------------------------------
    1.4 Workaround
    When the address of a function is assigned to a pointer, make sure to declare or define the function using type modifier "far".
         -----------------------------------------------------------------
         far int func(void);
         -----------------------------------------------------------------
    1.5 Schedule of Fixing Problem
    We plan to fix this problem in our next release.



    NC308WA Precaution
    MESCT-NC308WA_2-001216D

  2. Problem on Using a Structure as an Actual Argument of a Function with Varying Numbers of Arguments
    2.1 Versions Concerned
    NC308WA V.1.00 Release 1 ~ V.3.10 Release 1

    2.2 Description
    If a structure whose size is an odd number of bytes is used as an actual argument to a function with varying numbers of arguments, no actual arguments described after the structure are accessible.

    2.3 Conditions
    This problem occurs if the following four conditions are satisfied:
    (1) The va_arg macro that is defined in the "stdarg.h" file is used.
    (2) The second argument to the va_arg macro is a structure the size of which is an odd number of bytes.
    (3) The last of the declared formal arguments to a function that takes varying numbers of arguments or the actual argument corresponding to an omitted formal argument is a structure the size of which is an odd number of bytes.
    (4) Another actual argument is described after the structure in (3) above.
    [Example]
          --------------------------------------------------------------
          #include <stdarg.h>
     
          struct s {         /* A structure with an odd number of bytes */
              long    l;
              char    c;
          };
    
          int func(int a,...);
    
          int main(void)
          {
              struct s    s1;
              i = func(1, s1, 0x1234);    /* Conditions (3) and (4) */
          }
    
          int func(int a,...)
          {
              int       ii;
              struct s  s2;
              va_list   ap;
              va_start(ap, a);
    
              s2 = va_arg(ap, struct s);  /* Conditions (1) and (2) */
              ii = va_arg(ap, int);       /* Conditions (1) and (4) */
    
              va_end(ap);
              return ii;
          }
          --------------------------------------------------------------
    * In the above example, argument 0x1234 in "i = func(1, s1, 0x1234);" cannot be accessed correctly.

    2.4 Workaround
    Every structure used as an actual argument to a function with varying numbers of arguments must be defined as an even number of bytes in size by declaring a dummy data.
         -----------------------------------------------------------------
         struct s {
             long    l;
             char    c;
             char    dummy; /* padding */
         };
         -----------------------------------------------------------------
    2.5 Schedule of Fixing Problem
    We plan to fix this problem in our next release.





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