
running sizeof on a boost::int8_t returns 1, but what is the type? int/char? thanks.

It's type is 'boost::int8_t' which guarantees it to have the size of 8 bits
or 1 byte. Probably it is a typedef to some template instantiation.
If you ask which underlying type is used to implement it, than it is
probably char. As far as I remember C++ standard guarantees a char to have
the size of 1 byte. But anyway you can take a look at the implementation of
boost::int8_t.
Regards,
Ovanes
On Wed, Dec 16, 2009 at 4:00 PM, eial@cs.bgu.ac.il
running sizeof on a boost::int8_t returns 1, but what is the type? int/char?
thanks.

running sizeof on a boost::int8_t returns 1, but what is the type? int/char?
It's type is 'boost::int8_t' which guarantees it to have the size of 8 bits or 1 byte. Probably it is a typedef to some template instantiation. If you ask which underlying type is used to implement it, than it is probably char. As far as I remember C++ standard guarantees a char to have the size of 1 byte. But anyway you can take a look at the implementation of boost::int8_t.
Hopefully signed char, as I would expect 'int' anything to be signed. Tony

running sizeof on a boost::int8_t returns 1, but what is the type? int/char?
Strictly speaking you're not allowed to ask that question... it's a secret :-) The idea is that int8_t is whatever platform-dependent type has 8-bits and is signed. But since you ask, it's "signed char" on any platform you're ever likely to encounter. You should never make any assumptions about the actual types of the int#_t typedefs though - some of them really are "unmentionable" platform dependent types on some platforms - but take a look at boost/cstdint.hpp for the details. HTH, John.

John Maddock wrote:
running sizeof on a boost::int8_t returns 1, but what is the type? int/char?
Strictly speaking you're not allowed to ask that question... it's a secret :-)
The idea is that int8_t is whatever platform-dependent type has 8-bits and is signed.
But since you ask, it's "signed char" on any platform you're ever likely to encounter. You should never make any assumptions about the actual types of the int#_t typedefs though - some of them really are "unmentionable" platform dependent types on some platforms - but take a look at boost/cstdint.hpp for the details.
HTH, John.
This is a subject I accidently revisited recently. I wanted a arithmetic type that was only 8 bits long. boost::int8_t seemed just the ticket. But then when one did something like boost::int8_t i; std::cout << i; One usually wouldn't get what he would expect. To me this is a big "hole" in the whole concept. What I would really like to see is: int8_t defined with something like BOOST_SERIALIZATION_STRONGTYPEDEF so that int8_t becomes a true type rather than just a "macro" of some other type. To me - we should have a whole new set of (true) numeric types and start to use them. I sort of suspect that C99 had this intention, but by using typedef to implement them, they aren't useful for my needs. Perhaps the "mistake" is not having typedef create a truely new type. Or maybe a new keyword "strong_typedef". I realize that fixing this would be a herculean task at this point so this isn't a real suggestion - its really just a rant. But it makes me feel better. Robert Ramey

On Wed, Dec 16, 2009 at 12:12 PM, Robert Ramey
Perhaps the "mistake" is not having typedef create a truely new type. Or maybe a new keyword "strong_typedef".
Kinda like D's typedefs (~ your strong_typedef) v.s. its aliases (~ C/C++ typedef) http://www.digitalmars.com/d/1.0/type.html (search for typedef) http://www.digitalmars.com/d/1.0/comparison.html#StrongTypedefs
participants (8)
-
Dominique Devienne
-
eial@cs.bgu.ac.il
-
Gottlob Frege
-
John Maddock
-
Ovanes Markarian
-
Patrick Horgan
-
Robert Ramey
-
Rudolf Leitgeb