Non-Standard Type Sizes - Networking

Hello there!

So to clarify the title, it's not guaranteed that an "int" for example will be the same size from compiler to compiler. Of course there are standardized integers you can use that are guaranteed to be a certain amount of bytes.

I've been working on adding networking to an application I'm working on, and I'm not sure what the best way to handle this is. I'm using the networking library ENet. That basically lets you send and receive whatever data you want stored in a void pointer. Of course I can also interpret it as a C string as well if I wanted to and I COULD read values by converting the string into the values I'm looking for. I feel like that's too limiting.

Is there any downside to just forcing the programmer to use integers and whatnot of standard sizes? So in64_t, uint32_t, etc.

I would like networking to be rather robust and simple using some kind of template like CNetworkVar< int > m_iMyInt; However, using a plain int would open me up to potential size issues, and that's not good.

So what would be a good way to approach this problem?
Last edited on
Use plain text.

When you feel the urge to design a complex binary file format, or a complex binary application protocol, it is generally wise to lie down until the feeling passes.
...
Designing a textual protocol tends to future-proof your system. One specific reason is that ranges on numeric fields aren't implied by the format itself. Binary formats usually specify the number of bits allocated to a given value, and extending them is difficult.
http://catb.org/~esr/writings/taoup/html/ch05s01.html
Topic archived. No new replies allowed.