[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


Suspicious Assignments to Enumerations and Incorrect Function Returns

If the Extended Error Checking option is on, the C compiler generates a warning (not an error) if it encounters one of these syntax problems:

This would be OK:


void main() /* function declared to return void */
{
    printf ("hello world\n");
}

  • Assigning an integer or floating-point value to an enum type. For example:

  • enum Day { Sunday, Monday, Tuesday, Wednesday, 
                          Thursday, Friday, Saturday } d;
    
    d = 5;                        /* WARNING */
    d = Monday;              /* OK */
    d = (Day)3    ;          /* OK */

  • An empty return statement (return;) in a function that is not declared void. For example, this code would generate a warning:

  • int MyInit(void)
    {
        int err = GetMyResources();
      if (err !=0) return;  /* ERROR: Empty return statement */
    
      /* ... */

    This would be OK:


    int MyInit(void)
    {
        int err = GetMyResources();
        if (err!=0) return -1; /* OK */
    
      /* ... */

    The Extended Error Checking option corresponds to the pragma extended_errorcheck, described at "extended_errorcheck." To check whether this option is on, use __option (extended_errorcheck). See "Checking Options" for information on how to use this directive.


    [ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

    Visit the Metrowerks website at: http://www.metrowerks.com
    For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
    Copyright © 2000, Metrowerks Corp. All rights reserved.

    Last updated: August 17, 2000