开发者

int in c/c++ of various size

开发者 https://www.devze.com 2023-03-26 03:02 出处:网络
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 imp

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


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.


I'm not sure this is what you want but.. does this work for you ?

struct data {
    uint32_t int4;
    uint16_t int2;
};


Your 4 byte value will be an unsigned long and the 2 byte value will be an unsigned short.

0

精彩评论

暂无评论...
验证码 换一张
取 消