What header file is there where the acceleration library defines its own primitive data type?
Lately I've been trying to use the boost :: spirit: qi binary parser to parse some binary data, platform entity dependent. There is a simple example like:
Using declarations and variables:
using boost :: spirit :: qi :: little_word; using boost :: spirit :: qi :: little_dword; using boost :: spirit :: qi :: little_qword; boost :: uint16_t us; boost :: uint32_t ui; boost :: uint64_t ul;
Basic usage of small number binary parsers:
test_parser_attr("\x01\x02", little_word, us); assert(us == 0x0201);
test_parser_attr("\x01\x02\x03\x04", little_dword, ui); assert(ui == 0x04030201);
test_parser_attr("\x01\x02\x03\x04\x05\x06\x07\x08", little_qword, ul);
assert(ul == 0x0807060504030201LL);
test_parser("\x01\x02", little_word(0x0201));
test_parser("\x01\x02\x03\x04", little_dword(0x04030201));
test_parser("\x01\x02\x03\x04\x05\x06\x07\x08",
little_qword(0x0807060504030201LL));
It works really well. But the question is, why do we need to use some types of data, such as boost::uint16_t
, boost::uint32_t
here? Can I use unsigned long
or unsigned int
here? And if I want to parse double
or float
data type, what formatting data type should I use? And please tell me where is boost, define the above types?
a source to share
There are types such as uint16_t or uint32_t, so you can declare a variable with a specific bit width. You cannot do this with regular types such as "long" because they are of different sizes on different architectures and / or implementations. The above types are usually inferred by computation of a preprocessor resulting in the typing of a particular implementation / architecture type to obtain that particular size.
a source to share
The file <boost/cstdint.hpp>
contains all definitions boost::(u)int(8|16|32|64)_t
. This is mainly because MSVC does not ship with <cstdint>
. In C ++ compilers, which are also C compilers (like gcc), it <boost/cstdint.hpp>
just imports <cstdint>
into the boost namespace.
see also: stdint.h
a source to share