Thread: 'short' question

  1. #1
    ---
    Join Date
    May 2004
    Posts
    1,379

    'short' question

    given these sizes, what is the use of the short keyword?
    Type Size Range
    unsigned char 8 bits 0 to 255
    char 8 bits -128 to 127
    unsigned int 16 bits 0 to 65,535
    short int 16 bits -32,768 to 32,767
    int 16 bits -32,768 to 32,767

    unsigned long 32 bits 0 to 4,294,967,295
    long 32 bits -2,147,483,648 to 2,147,483,647
    float 32 bits 1.17549435 * (10^-38) to 3.40282347 * (10^+38)
    double 64 bits 2.2250738585072014 * (10^-308) to 1.7976931348623157 * (10^+308)
    long double 80 bits 3.4 * (10^-4932) to 1.1 * (10^4932)

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    What compiler did you get these sizes from? In Visual c++ 6 an int is a long int. If your compiler defines int the same as a short int then you can type either to get the same result.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    11
    Quote Originally Posted by sand_man
    given these sizes, what is the use of the short keyword?
    In your example short and int are the same thing. This isn't always true. In some systems (particularly windows) int is a 32 bit value.

    short is guaranteed to be 16 bits as is unsigned short

    int will be the size of the CPU's registers on whatever platform you're working.

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Technically, sizeof any data type is "implementation defined". However, each implementation will choose to use a particular "industry standard" data-type model.

    http://www.unix.org/version2/whatsnew/lp64_wp.html

    Under any model, "short" is identical to "short int".

    gg

  5. #5
    ---
    Join Date
    May 2004
    Posts
    1,379
    Thanks, I found that info from here http://www.acm.uiuc.edu/webmonkeys/b...html#variables
    Not from a compiler

  6. #6
    Registered User
    Join Date
    Mar 2005
    Posts
    11
    Quote Originally Posted by sand_man
    Thanks, I found that info from here http://www.acm.uiuc.edu/webmonkeys/b...html#variables
    Not from a compiler
    Safe bet... always take your compiler's documetation as more meaningful than some generic (and probably old) programming tutor.

    As someone else mentioned, the definitions do vary from one implementation to another. (so much for "standard" C).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. int and unsignd short
    By a0161 in forum C Programming
    Replies: 2
    Last Post: 11-11-2008, 04:14 AM
  2. Exam Question - Possible Mistake?
    By Richie T in forum C++ Programming
    Replies: 15
    Last Post: 05-08-2006, 03:44 PM
  3. Simple Short Class Question
    By Travis Dane in forum C++ Programming
    Replies: 2
    Last Post: 12-24-2002, 07:12 PM
  4. traversal of tree (short question)
    By mackol in forum C Programming
    Replies: 5
    Last Post: 11-25-2002, 08:41 AM
  5. Replies: 1
    Last Post: 01-23-2002, 03:34 AM