标题: 是不是GCC的BUG?
souldump
小试牛刀
Rank: 2
注册用户



UID 126416
精华 0
积分 5(积分有什么用?)
帖子 153
阅读权限 10
注册 2005-7-9
状态 离线
发表于 2007-4-3 21:43  资料  个人空间  短消息  加为好友 
是不是GCC的BUG?

#include <stdio.h>
u
^ X7m7x _jY2}
#include <stdlib.h>
s Yu*]@#U:h&epZ2qV#include <string.h>
iL|#n5l'Q4H#include <sys/un.h>Linux伊甸园论坛;ia
s+Z:[#C ^

#include <sys/types.h>www.linuxeden.comD'WL9^\4W8I
#include <sys/socket.h>
xZ"yp2u/Aowww.linuxeden.com#include <netinet/in.h>
8{        Nn8jSo V3?i;Owww.linuxeden.com#include <unistd.h>
        Rz
pxpK-`Ae
j
#include <errno.h>b&ip*R%H

W'Z4k`&y#@5uchar *O!][R,r e],u
sock_ntop(const struct sockaddr *sa, socklen_t salen)
t?0MU*y)Fj

{%}`.`.Q(iyC1Y:H0b
    char        portstr[8];mTf&S+GH
    static char str[128];        /* Unix domain is largest */t6r!R?'H.\{
www.linuxeden.com:I.[C8w7O-rk
D

    switch (sa->sa_family) {3F{6nYK
o&{#D

    case AF_INET: {%Yx{ _9zS
        struct sockaddr_in    *sin = (struct sockaddr_in *) sa;
J$z&\$l
lc,MD8dwww.linuxeden.com

@P^\b0I        if ( inet_ntop(AF_INET, &sin->sin_addr, str, sizeof(str)) == NULL)8N
R%IECfV9c        Dy

            return(NULL);
nA1C'z        ]-c        if (ntohs(sin->sin_port) != 0) {
3{
^#@)gA
            snprintf(portstr, sizeof(portstr), ":%d", ntohs(sin->sin_port));
-p1m
O#Gt@'`,VLinux伊甸园论坛
            strcat(str, portstr);
1Rd:_P"V#QLinux伊甸园论坛        }8Od0c~)iG%?
        return(str);mf`u+aQ
    }
2Mq6Lu4saI    default:
7T O%tG        s;X
A1V
        snprintf(str, sizeof(str), "sock_ntop: unknown AF_xxx: %d, len %d",
!VX)fq a{"w"@xS5F
|
                 sa->sa_family, salen);
4xEO3m        gtc
URf
        return(str);www.linuxeden.com
f,n5sG1}+LwO_

    }
BcJ0z%s$fhw    return (NULL);kX1N2c"^k&[
} /** end sock_ntop **/9I8@ z%Pps8tb

(i{{/h9b0G+Zm这个函数,我用gcc -c 编译时提示:
%W9`.G)@u*n,ELinux伊甸园论坛sockaddr.c: 在函数 ‘sock_ntop’ 中: |?YK)Ced n
sockaddr.c:340: 警告:比较指针和整数YN4|PE8a!T+it
就是这句: ( inet_ntop(AF_INET, &sin->sin_addr, str, sizeof(str)) == NULL)
$I/TE(Ak.da$@XLinux伊甸园论坛这是UNP上的代码,但是如果我给改成:
4[+fW3P%J0z ( ! inet_ntop(AF_INET, &sin->sin_addr, str, sizeof(str)))
kJ]*x
w ~&c#N_

就没有警告了,(J9Lb\B\4v"`1x
这是不是GCC的BUG?
p'h5D!J{:z ?&P5dU3f_B为何inet_ntop的返回值类型被认为是整型??

顶部
不容错过的IBM 集群技术资源汇总
zhuomingliang
自由撰稿人
Rank: 4
荣誉版主



UID 131385
精华 21
积分 4(积分有什么用?)
帖子 2537
阅读权限 10
注册 2005-8-26
状态 离线
发表于 2007-4-4 08:36  资料  个人空间  主页 短消息  加为好友 
不是,如果返回是整形,就不会出错了

顶部
 



当前时区 GMT+8, 现在时间是 2008-5-17 09:57

    Powered by Discuz! 5.5.0  © 2001-2007 Comsenz Inc.
Processed in 0.078794 second(s), 5 queries

清除 Cookies - 联系我们 - Linux伊甸园 - Archiver - WAP