什么是结构类型内部的可变尺寸类型

时间:2015-01-20 05:51:38

标签: c linux gcc

我正在尝试在项目nodogsplash中添加一个额外的功能。

struct addrlist_t {                                                    
        struct in_addr h_addr;
        struct addrlist_t *next;                                       
} *addrhead = NULL, *cur = NULL;

我在x86_64工作,sizeof(struct addrlist_t)返回8个字节,我想这里应该是16个字节。 奇怪的是&cur->h_addr&cur->next的指针是相同的。 然后我在其他程序中检查struct addrlist_t,它运行正常。

gdb说: 尝试解析出现在结构类型

内部的可变大小的类型

任何人都可以给我一些帮助。

我检查gcc -E

7812  struct hostent *he;                                                            
7813  struct addrlist_t {                                                            
7814   struct in_addr h_addr_list[0];                                                
7815   struct addrlist_t *next;                                                      
7816  } *addrhead = ((void *)0), *cur = ((void *)0);                                 
7817  struct addrlist_t **ppre = &addrhead;     

1 个答案:

答案 0 :(得分:1)

我发现了错误。

我使用的gethostbyname包括#include <netdb.h>

       struct hostent {
           char  *h_name;            /* official name of host */
           char **h_aliases;         /* alias list */
           int    h_addrtype;        /* host address type */
           int    h_length;          /* length of address */
           char **h_addr_list;       /* list of addresses */
       }
       #define h_addr h_addr_list[0] /* for backward compatibility */

h_addr是错误定义的。

相关问题