revjim.net

I am a C++ masta… well… not really

I debugged C++ code last night. Go me!

The problem was this:

int client_len;

/* code code code */

accept(SOCK_STREAM, (struct sockaddr *) &CLIENT_ADDR, &client_len);

The fix, was to declare client_len like this:

socklen_t client_len;

The funny thing, was that, if I took out all the C++ code, and compiled it as C code, the thing would work just fine with client_len being an int. There must be something different that happens (maybe because of a #define or something) that forces accept() to take a different parameter type for the third parameter. I don’t know enough C or C++ to know why it doesn’t work. I was just proud that I figured out how to fix it.

And I did it without any documentation on the accept() call. I just read all of the #include-d files until I found an accept() definition.

Very interesting.