invalid type argument of ‘->’ (have ‘fd_set’)












1















I know it's not the first thread with this error but I really can't get what's wrong... My code is bellow:



/* File descriptor sets */
struct descs {
fd_set read;
fd_set write;
fd_set except;
};

typedef struct descs descs_t;

/* Server representation */
struct server {
int sock; /* Server sock descriptor */
struct sockaddr_in addr; /* Server address */
socklen_t addrlen; /* Server address size */
char buffer[BUFFER_SIZE]; /* Message buffer */
int len; /* Message buffer length */
};

typedef struct server server_t;

void build_fds(struct server *srv, struct descs *fd) {
FD_ZERO(fd->read);
FD_SET(STDIN_FILENO, fd->read);
FD_SET(srv->sock, fd->read);

FD_ZERO(fd->write);
// there is smth to send, set up write_fd for server socket
if (srv->len > 0) {
FD_SET(srv->sock, fd->write);
}

FD_ZERO(fd->except);
FD_SET(STDIN_FILENO, fd->except);
FD_SET(srv->sock, fd->except);
}


I am passing my struct via pointer so I must use -> but it crashes with errors:



chatcl.c: In function ‘build_fds’:
chatcl.c:37: error: invalid type argument of ‘->’ (have ‘fd_set’)
chatcl.c:38: error: invalid type argument of ‘->’ (have ‘fd_set’)
chatcl.c:39: error: invalid type argument of ‘->’ (have ‘fd_set’)
chatcl.c:41: error: invalid type argument of ‘->’ (have ‘fd_set’)
chatcl.c:44: error: invalid type argument of ‘->’ (have ‘fd_set’)
chatcl.c:47: error: invalid type argument of ‘->’ (have ‘fd_set’)
chatcl.c:48: error: invalid type argument of ‘->’ (have ‘fd_set’)
chatcl.c:49: error: invalid type argument of ‘->’ (have ‘fd_set’)
make: *** [chatcl] Error 1


What's wrong in my code?










share|improve this question



























    1















    I know it's not the first thread with this error but I really can't get what's wrong... My code is bellow:



    /* File descriptor sets */
    struct descs {
    fd_set read;
    fd_set write;
    fd_set except;
    };

    typedef struct descs descs_t;

    /* Server representation */
    struct server {
    int sock; /* Server sock descriptor */
    struct sockaddr_in addr; /* Server address */
    socklen_t addrlen; /* Server address size */
    char buffer[BUFFER_SIZE]; /* Message buffer */
    int len; /* Message buffer length */
    };

    typedef struct server server_t;

    void build_fds(struct server *srv, struct descs *fd) {
    FD_ZERO(fd->read);
    FD_SET(STDIN_FILENO, fd->read);
    FD_SET(srv->sock, fd->read);

    FD_ZERO(fd->write);
    // there is smth to send, set up write_fd for server socket
    if (srv->len > 0) {
    FD_SET(srv->sock, fd->write);
    }

    FD_ZERO(fd->except);
    FD_SET(STDIN_FILENO, fd->except);
    FD_SET(srv->sock, fd->except);
    }


    I am passing my struct via pointer so I must use -> but it crashes with errors:



    chatcl.c: In function ‘build_fds’:
    chatcl.c:37: error: invalid type argument of ‘->’ (have ‘fd_set’)
    chatcl.c:38: error: invalid type argument of ‘->’ (have ‘fd_set’)
    chatcl.c:39: error: invalid type argument of ‘->’ (have ‘fd_set’)
    chatcl.c:41: error: invalid type argument of ‘->’ (have ‘fd_set’)
    chatcl.c:44: error: invalid type argument of ‘->’ (have ‘fd_set’)
    chatcl.c:47: error: invalid type argument of ‘->’ (have ‘fd_set’)
    chatcl.c:48: error: invalid type argument of ‘->’ (have ‘fd_set’)
    chatcl.c:49: error: invalid type argument of ‘->’ (have ‘fd_set’)
    make: *** [chatcl] Error 1


    What's wrong in my code?










    share|improve this question

























      1












      1








      1








      I know it's not the first thread with this error but I really can't get what's wrong... My code is bellow:



      /* File descriptor sets */
      struct descs {
      fd_set read;
      fd_set write;
      fd_set except;
      };

      typedef struct descs descs_t;

      /* Server representation */
      struct server {
      int sock; /* Server sock descriptor */
      struct sockaddr_in addr; /* Server address */
      socklen_t addrlen; /* Server address size */
      char buffer[BUFFER_SIZE]; /* Message buffer */
      int len; /* Message buffer length */
      };

      typedef struct server server_t;

      void build_fds(struct server *srv, struct descs *fd) {
      FD_ZERO(fd->read);
      FD_SET(STDIN_FILENO, fd->read);
      FD_SET(srv->sock, fd->read);

      FD_ZERO(fd->write);
      // there is smth to send, set up write_fd for server socket
      if (srv->len > 0) {
      FD_SET(srv->sock, fd->write);
      }

      FD_ZERO(fd->except);
      FD_SET(STDIN_FILENO, fd->except);
      FD_SET(srv->sock, fd->except);
      }


      I am passing my struct via pointer so I must use -> but it crashes with errors:



      chatcl.c: In function ‘build_fds’:
      chatcl.c:37: error: invalid type argument of ‘->’ (have ‘fd_set’)
      chatcl.c:38: error: invalid type argument of ‘->’ (have ‘fd_set’)
      chatcl.c:39: error: invalid type argument of ‘->’ (have ‘fd_set’)
      chatcl.c:41: error: invalid type argument of ‘->’ (have ‘fd_set’)
      chatcl.c:44: error: invalid type argument of ‘->’ (have ‘fd_set’)
      chatcl.c:47: error: invalid type argument of ‘->’ (have ‘fd_set’)
      chatcl.c:48: error: invalid type argument of ‘->’ (have ‘fd_set’)
      chatcl.c:49: error: invalid type argument of ‘->’ (have ‘fd_set’)
      make: *** [chatcl] Error 1


      What's wrong in my code?










      share|improve this question














      I know it's not the first thread with this error but I really can't get what's wrong... My code is bellow:



      /* File descriptor sets */
      struct descs {
      fd_set read;
      fd_set write;
      fd_set except;
      };

      typedef struct descs descs_t;

      /* Server representation */
      struct server {
      int sock; /* Server sock descriptor */
      struct sockaddr_in addr; /* Server address */
      socklen_t addrlen; /* Server address size */
      char buffer[BUFFER_SIZE]; /* Message buffer */
      int len; /* Message buffer length */
      };

      typedef struct server server_t;

      void build_fds(struct server *srv, struct descs *fd) {
      FD_ZERO(fd->read);
      FD_SET(STDIN_FILENO, fd->read);
      FD_SET(srv->sock, fd->read);

      FD_ZERO(fd->write);
      // there is smth to send, set up write_fd for server socket
      if (srv->len > 0) {
      FD_SET(srv->sock, fd->write);
      }

      FD_ZERO(fd->except);
      FD_SET(STDIN_FILENO, fd->except);
      FD_SET(srv->sock, fd->except);
      }


      I am passing my struct via pointer so I must use -> but it crashes with errors:



      chatcl.c: In function ‘build_fds’:
      chatcl.c:37: error: invalid type argument of ‘->’ (have ‘fd_set’)
      chatcl.c:38: error: invalid type argument of ‘->’ (have ‘fd_set’)
      chatcl.c:39: error: invalid type argument of ‘->’ (have ‘fd_set’)
      chatcl.c:41: error: invalid type argument of ‘->’ (have ‘fd_set’)
      chatcl.c:44: error: invalid type argument of ‘->’ (have ‘fd_set’)
      chatcl.c:47: error: invalid type argument of ‘->’ (have ‘fd_set’)
      chatcl.c:48: error: invalid type argument of ‘->’ (have ‘fd_set’)
      chatcl.c:49: error: invalid type argument of ‘->’ (have ‘fd_set’)
      make: *** [chatcl] Error 1


      What's wrong in my code?







      c struct






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 19 at 9:45









      ШахШах

      2,25851945




      2,25851945
























          2 Answers
          2






          active

          oldest

          votes


















          3














          You are missing the &, i.e. you need the address of the data structure, e.g.



          #include <sys/select.h>

          struct descs {
          fd_set a;
          };

          void func(struct descs *d) {
          FD_ZERO(&d->a);
          }





          share|improve this answer
























          • Thank you very much! I didn't know about it even.

            – Шах
            Jan 19 at 9:58



















          2














          From man select the FD_* macros they take pointers to fd_set:



             void FD_CLR(int fd, fd_set *set);
          int FD_ISSET(int fd, fd_set *set);
          void FD_SET(int fd, fd_set *set);
          void FD_ZERO(fd_set *set);


          You should pass pointers to the functions (macros), not values. You can use the address-of operator:



          FD_ZERO(&fd->read);
          FD_SET(STDIN_FILENO, &fd->read);
          FD_SET(srv->sock, &fd->read);


          and so on.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54265824%2finvalid-type-argument-of-have-fd-set%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            You are missing the &, i.e. you need the address of the data structure, e.g.



            #include <sys/select.h>

            struct descs {
            fd_set a;
            };

            void func(struct descs *d) {
            FD_ZERO(&d->a);
            }





            share|improve this answer
























            • Thank you very much! I didn't know about it even.

              – Шах
              Jan 19 at 9:58
















            3














            You are missing the &, i.e. you need the address of the data structure, e.g.



            #include <sys/select.h>

            struct descs {
            fd_set a;
            };

            void func(struct descs *d) {
            FD_ZERO(&d->a);
            }





            share|improve this answer
























            • Thank you very much! I didn't know about it even.

              – Шах
              Jan 19 at 9:58














            3












            3








            3







            You are missing the &, i.e. you need the address of the data structure, e.g.



            #include <sys/select.h>

            struct descs {
            fd_set a;
            };

            void func(struct descs *d) {
            FD_ZERO(&d->a);
            }





            share|improve this answer













            You are missing the &, i.e. you need the address of the data structure, e.g.



            #include <sys/select.h>

            struct descs {
            fd_set a;
            };

            void func(struct descs *d) {
            FD_ZERO(&d->a);
            }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 19 at 9:54









            Stefan BeckerStefan Becker

            1,459216




            1,459216













            • Thank you very much! I didn't know about it even.

              – Шах
              Jan 19 at 9:58



















            • Thank you very much! I didn't know about it even.

              – Шах
              Jan 19 at 9:58

















            Thank you very much! I didn't know about it even.

            – Шах
            Jan 19 at 9:58





            Thank you very much! I didn't know about it even.

            – Шах
            Jan 19 at 9:58













            2














            From man select the FD_* macros they take pointers to fd_set:



               void FD_CLR(int fd, fd_set *set);
            int FD_ISSET(int fd, fd_set *set);
            void FD_SET(int fd, fd_set *set);
            void FD_ZERO(fd_set *set);


            You should pass pointers to the functions (macros), not values. You can use the address-of operator:



            FD_ZERO(&fd->read);
            FD_SET(STDIN_FILENO, &fd->read);
            FD_SET(srv->sock, &fd->read);


            and so on.






            share|improve this answer




























              2














              From man select the FD_* macros they take pointers to fd_set:



                 void FD_CLR(int fd, fd_set *set);
              int FD_ISSET(int fd, fd_set *set);
              void FD_SET(int fd, fd_set *set);
              void FD_ZERO(fd_set *set);


              You should pass pointers to the functions (macros), not values. You can use the address-of operator:



              FD_ZERO(&fd->read);
              FD_SET(STDIN_FILENO, &fd->read);
              FD_SET(srv->sock, &fd->read);


              and so on.






              share|improve this answer


























                2












                2








                2







                From man select the FD_* macros they take pointers to fd_set:



                   void FD_CLR(int fd, fd_set *set);
                int FD_ISSET(int fd, fd_set *set);
                void FD_SET(int fd, fd_set *set);
                void FD_ZERO(fd_set *set);


                You should pass pointers to the functions (macros), not values. You can use the address-of operator:



                FD_ZERO(&fd->read);
                FD_SET(STDIN_FILENO, &fd->read);
                FD_SET(srv->sock, &fd->read);


                and so on.






                share|improve this answer













                From man select the FD_* macros they take pointers to fd_set:



                   void FD_CLR(int fd, fd_set *set);
                int FD_ISSET(int fd, fd_set *set);
                void FD_SET(int fd, fd_set *set);
                void FD_ZERO(fd_set *set);


                You should pass pointers to the functions (macros), not values. You can use the address-of operator:



                FD_ZERO(&fd->read);
                FD_SET(STDIN_FILENO, &fd->read);
                FD_SET(srv->sock, &fd->read);


                and so on.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 19 at 9:54









                Kamil CukKamil Cuk

                10.3k1527




                10.3k1527






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54265824%2finvalid-type-argument-of-have-fd-set%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Homophylophilia

                    Updating UILabel text programmatically using a function

                    Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage