Afficher un message
Vieux 01/07/2008, 03h13   #2
Jim Langston
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: is the syntax for fixed-length integers the same for C and C++?

"darren" <minofifa@gmail.com> wrote in message
news:20f8c39a-7fa2-466d-b933-b2ab90df516b@i18g2000prn.googlegroups.com...
> 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.
>
> In my C++ code i've been using uint16_t and uint32_t for fixed length
> integers. Are these two Types compatible?


There are no guarantees, but most likely, yes, they are the same. To find
out search through your code where uint32_t and uint_32 are defined and make
sure they are the same. For all likelyhood they will be the same. It's a
good idea to check though.

> 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.


Well, is it your code on the other end of the network also? If it's your
code then it will be what you set it to. If it's not your code, you'll need
to check the documentation to see what they expect the size of their ints to
be.

But, yes, uint_xxx_t should be the the same size on each architecture. I'm
not positive it's declared in the standard, however, I don't have a copy of
the standard handy.


  Réponse avec citation
 
Page generated in 0,05274 seconds with 9 queries