postmaster.c 中的 ListenAddresses

在 postmaster.c 中看到这种代码,从Java程序员的角度,看起来是很不爽的:

char *ListenAddresses;
...
    if (ListenAddresses)
    {            
        char       *rawstring;            
        List       *elemlist;            
        ListCell   *l;                
...

到底何时 ListenAddress 的逻辑值为真呢?试作如下代码进行验证:

char *ListenAddresses;

int
main(int argc, char **argv)
{
       if (ListenAddresses){
             fprintf(stderr, "ListenAddresses is ok.\n");
        }else{
             fprintf(stderr, "ListenAddresses is NG.\n");
        }
    return 0;
}

编译后运行结果:ListenAddresses is NG.

再改改,运行看看:

char *ListenAddresses;

int
main(int argc, char **argv)
{
       
        ListenAddress="192.168.2.5";

        if (ListenAddress){
             fprintf(stderr, "ListenAddresses is ok.\n");
             fprintf(stderr, "ListenAddresses is %s.\n",ListenAddress);
        }else{
             fprintf(stderr, "ListenAddresses is NG.\n");
        }

    return 0;
}

运行结果:

ListenAdresses is ok.
ListenAddresses is 192.168.2.5.

posted @ 2012-07-17 15:47  健哥的数据花园  阅读(309)  评论(0编辑  收藏  举报