missing return statement

Discussion in 'Embedded Systems and Microcontrollers' started by embed_v, Sep 1, 2010.

  1. embed_v

    Thread Starter New Member

    Aug 30, 2010
    acually this code is the i2c master rx mode ,i am using lm3s600 ,keiluv4,
    but i get the warning for this,somthing is wrong in return statement so plz help meeee to solv this problem

    U8 I2c_Master_Receive(void) //Master Read/Receive operation

    I2C0_MASTER_MSA_R = SLAVEA; // I2C Slave Address,transmit slave address with write bit
    I2C0_MASTER_MCS_R = START; // The generation of a START
    // I2C0_MASTER_MCS_R = 0x0; // clear the START bit to avoid retransmit of STAR
    I2C0_MASTER_MIMR_R = 0x1; // enable i2c master interrupt.

    while( I2C0_MASTER_MCS_R == I2C_BUSY) // wait until I2C is no longer busy

    if (I2C0_MASTER_MCS_R == I2C_OK)

    return I2C0_MASTER_MDR_R; // if operation was successful then return read value


    return 0xFF; // return a constant value if there was an error


    ther is an warning:
    i2c.c(81): warning: #940-D: missing return statement at end of non-void function "I2c_Master_Receive"
  2. Papabravo


    Feb 24, 2006
    Your problem is the missing null statement consisting of a semi-colon on the while statement. The following if-else is the statement of the while loop and thus when the while loop terminates there is no return statement that returns a value. The implicit return indicated by the closing brace does not have a value that it can return.

    If you would use curly braces more liberally and consistently this problem would not have occurred.
  3. hgmjr

    Retired Moderator

    Jan 28, 2005
    Indeed, as papabravo has stated, you clearly have a deficit in curly brackets. Their proper use will not only overcome your existing problem but will add greatly to the read-ability of the resultant code.