News for hackers. Stuff that matters.
Re:What If I Don't Actually Like My Users? (2008) by pdkl95 on Thursday June 02, 2016 @11:50PM (#11828173)
> -8. The compiler will warn if you get it right.

> bind() socket library call ... takes a struct sockaddr [when you are usually using a struct sockaddr_in]

Except the compiler is correct. If you want to use a polymorphic type in a generic call that requires the parent type, you should include a cast.

From the example in my man page for bind(2):

    int main(int argc, char *argv[])
    {
        int sfd;
        struct sockaddr_un my_addr;
    
        /* ... */
          
        if (bind(sfd, (struct sockaddr *) &my_addr,
                   sizeof(struct sockaddr_un)) == -1)
            handle_error("bind");

        /* ,,, */
Re:What If I Don't Actually Like My Users? (2008) by sjolsen on Friday June 03, 2016 @02:24AM (#11828683)
I don't think the complaint is that the compiler won't accept a struct sockaddr_in* where the API expects a struct sockaddr* . I think the complaint is that the API is designed in such a way that obtaining the required struct sockaddr* involves casting between incompatible types. There are more robust ways of doing type erasure, even in C.