Thread: integer promotions

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    50

    integer promotions

    I came across the foll code in c99 standard:

    Otherwise, if the type of the operand with signed integer type can represent
    all of the values of the type of the operand with unsigned integer type, then
    the operand with unsigned integer type is converted to the type of the
    operand with signed integer type.

    Can someone please give an example for this?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Suppose x is an unsigned int and y is a long. Suppose also that UINT_MAX is 65535 and LONG_MAX is 2147483647. Therefore, if we look at the expression (x + y), we see that "the type of the operand with signed integer type can represent all of the values of the type of the operand with unsigned integer type", hence x is converted to long.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    50
    Quote Originally Posted by laserlight View Post
    Suppose x is an unsigned int and y is a long. Suppose also that UINT_MAX is 65535 and LONG_MAX is 2147483647. Therefore, if we look at the expression (x + y), we see that "the type of the operand with signed integer type can represent all of the values of the type of the operand with unsigned integer type", hence x is converted to long.
    Thank you...you rockkkkk!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. integral promotions
    By St0rM-MaN in forum C Programming
    Replies: 7
    Last Post: 06-28-2007, 04:37 PM
  2. Replies: 5
    Last Post: 06-12-2007, 02:18 PM
  3. determining if an integer is a legal integer
    By LiquidBlaze33 in forum C++ Programming
    Replies: 2
    Last Post: 10-09-2005, 07:06 PM
  4. finding an integer in an integer
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 05-09-2002, 07:25 PM
  5. determining integer/non-integer
    By gulakojhyau in forum C++ Programming
    Replies: 9
    Last Post: 03-08-2002, 01:25 PM

Tags for this Thread