简体   繁体   中英

Struct of Pointers

I'm trying to store an array of structs with each struct having pointers but I get a "initialization makes pointer from integer without a cast" message in creating the array.

struct fl_valueags {
   tcflag_t *fl_value;
   flagtype_t *fl_type;
};
...
 struct fl_valueags t_flags[] = { { ttyinfo->c_iflag, INPUT }, {
     ttyinfo->c_oflag, OUTPUT }, { ttyinfo->c_cflag, CONTROL }, {
       ttyinfo->c_lflag, LOCAL } };

You should pass the address of c_iflag :

struct fl_valueags t_flags[] = {    { &ttyinfo->c_iflag, INPUT }, 
                                    { &ttyinfo->c_oflag, OUTPUT }, 
                                    { &ttyinfo->c_cflag, CONTROL }, 
                                    { &ttyinfo->c_lflag, LOCAL } };

Regarding the fl_type , it should probably be declared as a value, not a pointer (unless INPUT, OUTPUT CONTROL and LOCAL are pointers):

struct fl_valueags {
   tcflag_t *fl_value;
   flagtype_t fl_type;
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM