On Mon, 30 Jun 2008 15:25:51 -0700 (PDT), darren <mi******@gmail.com>
wrote in comp.lang.c++:
Hi
I have an assignment that is in C and, for an API call, asks for a
uint_16 and uint_32 in one of its functions.
These are not standard C data types, so we can only guess at what they
are. They are some types defined by the author(s) of the library you
are using.
In my C++ code i've been using uint16_t and uint32_t for fixed length
integers. Are these two Types compatible?
The types int#_t and uint#_t are standard C data types, added in the
1999, and later, versions of the C language standard. They will be
added to the next revision of the C++ standard, most likely finalized
in the next year or so. But they are not part of standard C++ yet.
As Jim Langston already suggested, find the headers with the typedefs
for the non-standard uint_16, etc., and those for the standard
C/semi-standard C++ uint16_t, etc., and see if they are aliases for
the same underlying types.
On today's common 32-bit desktop platforms, it is quite possible that
uint_32 could be an alias for "unsigned int" but uint32_t an alias for
"unsigned long". Or vice versa. That could result in a large number
of complaints from the compiler, depending on which headers were
included with which source code.
Also, if i make a struct of a few variables of type uint_xxx_t, can I
be assured that this struct will be the same size on either end of the
wire when sent over a network (note, the hosts may not be the same
platform). I know that some architecture's treat int's as different
lengths, but I thought that is why we use uint_xxx_t, to solve that
poblem.
You can't ever assume binary layout compatibility across a network,
especially if different platform are involved. Even if the sizes of
the individual members were the same, structure alignment and padding
could result in the structure being two different sizes on the
different platforms.
And the representation of the integer types could be different, even
if they have the same number of bits. The most common difference is
big- versus little-endian.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://c-faq.com/
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html