Keil Logo

GENERAL: CONFLICTING FUNCTION TYPE AND RETURN TYPE


Information in this article applies to:

  • C166 Version 3.12
  • C166 Version 4.03
  • C251 Version 2.14
  • C51 Version 5.50

QUESTION

I have written the following code:

char foo(void)
{
  int x = 0xABCD;
  return x;
}

The returned value is truncated. Why is there no warning given for this situation?

ANSWER

The ANSI C Standard, section 6.6.6.4, states:

"If a return statement with an expression is executed, the value of the expression is returned to the caller as the value of the function call expression. If the expression has a type different from that of the function in which it appears, it is converted as if it were assigned to an object of that type."

So, rather than generating a warning, the int in the example above is simply converted to a char.

MORE INFORMATION

Refer to section 6.6.6.4 - 'The return statement' in the ANSI C Standard (ANSI/ISO 9899-1990).

Last Reviewed: Tuesday, July 19, 2005


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.