John Doe
John Doe

Reputation: 1

Recv() in Winsock requires signed buffer

I use recv() on Linux with unsigned char buffer and it works well.

But recv() on Windows requires signed char and I don't know why.

I thought the packet can be only ASCII character.

Should I use something like this (char)buffer?

Upvotes: 0

Views: 139

Answers (1)

Michael Chourdakis
Michael Chourdakis

Reputation: 11158

char, unsigned char and signed char are different types but all are 8 bit. In theory, all "buffers" should be unsigned char*. In practise, many functions use a plain char* including most Win32 APIs. In all such cases it is a plain 8-bit array.

In short, cast it freely.

Cases that actually need a char rather than an unsigned char should be obvious to detect and handle.

As per @JJ comment, you also have std::byte for raw 8-bit stuff without character characteristics, similar to BYTE in Win32.

Upvotes: 1

Related Questions