Reputation: 3975
I have to send Data via UDP. For that I need to create a struct. according to that format in which I have to send data there is an int of 4bytes and another int of 2 bytes. how to I implement that in C/C++
Upvotes: 0
Views: 123
Reputation: 41374
The size of types such as int
, long
, and long long
isn't strictly defined in C. If you want to specify integers of specific byte sizes, you should #include stdint.h and use int32_t
, uint16_t
, etc.
Upvotes: 5
Reputation:
Your 4 byte value will be an unsigned long
and the 2 byte value will be an unsigned short
.
Upvotes: 0
Reputation: 182619
I'm not sure this is what you want but.. does this work for you ?
struct data {
uint32_t int4;
uint16_t int2;
};
Upvotes: 3