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
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
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Ž
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.
I believe __int64 is also standard.Originally Posted by Desolation
Sent from my iPadŽ
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:
Which means it is the equivalent of a unsigned char.Code:typedef unsigned char unsigned __int8;
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.
I think it is as well but wouldn't you need a 64 bit processor ?Originally Posted by SlyMaelstrom
Which I must say is super lame especially if you expect your __int8 to output an integer without any cast.Originally Posted by Mario F.
Sent from my iPadŽ
They aren't typedefs in MSVC++. =]
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.
>> 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.
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Ž
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.
So unsigned short (2 bytes) is the same as unsigned int16?
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.
NONE of these are mentioned in the ANSI/ISO standard. (The leading undorescore is a hint.)
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.__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.
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.I believe __int64 is also standard....
...I think it is as well but wouldn't you need a 64 bit processor ?
Last edited by DougDbug; 09-27-2006 at 12:41 PM.