why omit unsigned int in unsuffixed decimal integer constant?

This is a discussion on why omit unsigned int in unsuffixed decimal integer constant? within the C Programming forums, part of the General Programming Boards category; Hi, In the K&R C II, Code: The type of an integer constant depends on its form, value and suffix. ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    48

    why omit unsigned int in unsuffixed decimal integer constant?

    Hi,

    In the K&R C II,
    Code:
    The type of an integer constant depends on its form, value and suffix. 
    (See Par.A.4 for a discussion of types). If it is unsuffixed and decimal, it 
    has the first of these types in which its value can be represented: int, 
    long int, unsigned long int. If it is unsuffixed, octal or hexadecimal, it 
    has the first possible of these types: int, unsigned int, long int, 
    unsigned long int. If it is suffixed by u or U, then unsigned int, unsigned 
    long int. If it is suffixed by l or L, then long int, unsigned long int. If an 
    integer constant is suffixed by UL, it is unsigned long.
    compared to int, unsigned int can represent bigger positive numbers, just like unsigned long vs. long. If int is assigned to 8 bits, then its range for positive number is [0, +127], while unsigned int is [0, +255]. An integer constant like 200 can be represented as unsigned int, which doesn't have to be long (which maybe has bigger bits than int).
    Just like unsuffixed octal and hex integer constants, they take an order int->unsigned int->long->unsigned log. I think this is more reasonable, don't understand why unsuffixed decimal integer skip unsigned int. Could anyone please explain it to me?

    THANKS!!

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,195
    An integer constant (unsuffixed decimal digits) is placed in a signed integral type, never in an unsigned one. The order in the 1999 C standard is int, long, long long NOT int, long, unsigned long,
    Right 98% of the time, and don't care about the other 3%.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    48
    Quote Originally Posted by grumpy View Post
    An integer constant (unsuffixed decimal digits) is placed in a signed integral type, never in an unsigned one. The order in the 1999 C standard is int, long, long long NOT int, long, unsigned long,
    I'm talking about C90 actually, and it does take the order int, long, unsigned long. Why never in an unsigned one? What about unsuffixed octal and hex integer constant? They can also be unsigned.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,401
    It could well be a matter of common usage: the decimal representation tends to see use with signed integer variables, so the type of the literal without suffix is only made unsigned when necessary, and then made only signed in C99. The octal and hexadecimal representations tend to see use with unsigned integer variables as they may be involved in bitwise operations, so prefering the unsigned version of an integer conversion rank to the signed version of the next rank makes sense.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Decimal to 16 bit unsigned?
    By blurx in forum C Programming
    Replies: 5
    Last Post: 10-16-2008, 01:56 PM
  2. Replies: 7
    Last Post: 06-01-2008, 07:47 AM
  3. integer constant is too large for type
    By Abda92 in forum C++ Programming
    Replies: 8
    Last Post: 02-09-2008, 10:47 AM
  4. How do I print 64 bit unsigned integer in hex?
    By electrolove in forum C Programming
    Replies: 7
    Last Post: 02-11-2003, 11:43 AM
  5. integer to constant char w/o using itoa()
    By kes103 in forum C++ Programming
    Replies: 1
    Last Post: 01-06-2003, 09:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21