uint8, 16 noob question

This is a discussion on uint8, 16 noob question within the C++ Programming forums, part of the General Programming Boards category; Hello.. What is meant by unsigned int8 (unsigned __int8) and 16? When is it being used? Whats the right way ...

  1. #1
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630

    uint8, 16 noob question

    Hello..

    What is meant by unsigned int8 (unsigned __int8) and 16? When is it being used? Whats the right way to use/define it in c++?

    Thanks for answers

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,066
    It's an unsigned 8-bit integer... meaning to say it accepts the values of 0-255 without overflowing.

    It can be used anywhere you need a really small integer... ever wonder why in most Final Fantasy games the highest a player stat can go is 255?
    Sent from my iPad®

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    903
    The number of bits used to represent the integer. I guess you use these versions when you need to be sure of the exact size of the variable you are creating. Simply stating 'int' only gives you an approximation on the size. You can also use these to increase the maximum possible value stored. Sometimes you could need a 'large' integer and store it in an unsigned __int32. For anything bigger than that, you'll need a big-number library like GMP.

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,066
    Quote Originally Posted by Desolation
    Sometimes you could need a 'large' integer and store it in an unsigned __int32. For anything bigger than that, you'll need a big-number library like GMP.
    I believe __int64 is also standard.
    Sent from my iPad®

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,412
    When in doubt, and if your IDE makes it easy to look for definitions, you can always search for the definition of a non user-defined type.

    unsigned __int8 is a typedef. Depending on your compiler implementation, it's quite possible that it is defined as:

    Code:
    typedef unsigned char unsigned __int8;
    Which means it is the equivalent of a unsigned char.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    903
    Quote Originally Posted by SlyMaelstrom
    I believe __int64 is also standard.
    I think it is as well but wouldn't you need a 64 bit processor ?

  7. #7
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,066
    Quote Originally Posted by Mario F.
    Which means it is the equivalent of a unsigned char.
    Which I must say is super lame especially if you expect your __int8 to output an integer without any cast.
    Sent from my iPad®

  8. #8
    Registered User
    Join Date
    May 2006
    Posts
    903
    They aren't typedefs in MSVC++. =]

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Nor are they "standard", except for in Microsoft compilers (I think).
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    >> I believe __int64 is also standard.
    I don't think any of the __intXX types are standard in C++. They are generally compiler extensions. All of the standard datatypes don't have specific bits lengths.

  11. #11
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,066
    So it would appear... in that case, I feel like they could make a decent addition to the standard (not as typedefs but actual types), because they've served me well in the past and I've yet to run into a compiler that didn't compile them.
    Sent from my iPad®

  12. #12
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    C99 has them. I think they're called intX_t and uintX_t in <stdint.h>.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  13. #13
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630
    So unsigned short (2 bytes) is the same as unsigned int16?

  14. #14
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Yes, except that an unsigned short could be larger than 2 bytes, whereas a uint16 (or a variation) will always be 2 bytes. This can be useful.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  15. #15
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    NONE of these are mentioned in the ANSI/ISO standard. (The leading undorescore is a hint.)

    __int8, __int16, __int32, __int64

    Microsoft Specific

    Microsoft C/C++ features support for sized integer types. You can declare 8-, 16-, 32-, or 64-bit integer variables by using the __intn type specifier, where n is 8, 16, 32, or 64.

    The following example declares one variable for each of these types of sized integers:

    __int8 nSmall; // Declares 8-bit integer
    __int16 nMedium; // Declares 16-bit integer
    __int32 nLarge; // Declares 32-bit integer
    __int64 nHuge; // Declares 64-bit integer

    The types __int8, __int16, and __int32 are synonyms for the ANSI types that have the same size, and are useful for writing portable code that behaves identically across multiple platforms. Note that the __int8 data type is synonymous with type char, __int16 is synonymous with type short, and __int32 is synonymous with type int. The __int64 type has no ANSI equivalent.

    C++ Specific
    Because __int8, __int16, and __int32 are considered synonyms by the compiler, care should be taken when using these types as arguments to overloaded function calls.
    But, much of C99 is going to be included in the new standard. I don't know the details, but I think I've read that long long int will be part of the new standard.

    I believe __int64 is also standard....

    ...I think it is as well but wouldn't you need a 64 bit processor ?
    No! The compiler can store a single variable in a series of consecutive memory locations. You can run Standard ANSI C/C++ on an 8-bit machine, even though Standard C/C++ requires a long int to hold at least 32 bits. If something is part of the standard, then it can't require any special hardware... All C++ compilers are supposed to include it.
    Last edited by DougDbug; 09-27-2006 at 12:41 PM.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. quick noob question
    By thanatos1 in forum C# Programming
    Replies: 2
    Last Post: 06-17-2009, 08:28 PM
  2. another noob question
    By clb2003 in forum C Programming
    Replies: 4
    Last Post: 02-12-2009, 12:28 PM
  3. Noob printf question
    By lolguy in forum C Programming
    Replies: 3
    Last Post: 12-14-2008, 07:08 PM
  4. Noob Question
    By bumfluff in forum C++ Programming
    Replies: 4
    Last Post: 11-06-2005, 03:36 AM
  5. SSH Hacker Activity!! AAHHH!!
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 03-06-2005, 02:53 PM

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