C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了这个C语言是什么(if(1))?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在openssl源代码中注意到一个奇怪的成语,here并重复如下:
if ((in == NULL) && (passwds == NULL)) {
        if (1) {                                    (* <---- HERE *)
#ifndef OPENSSL_NO_UI
            /* build a null-terminated list */
            static char *passwds_static[2] = { NULL,NULL };

            passwds = passwds_static;
            if (in == NULL)
                if (EVP_read_pw_string
                    (passwd_malloc,passwd_malloc_size,"Password: ",!(passed_salt || in_noverify)) != 0)
                    goto end;
            passwds[0] = passwd_malloc;
        } else {
#endif
            BIO_printf(bio_err,"password required\n");
            goto end;
        }
}

看来这段代码相当于:

if ((in == NULL) && (passwds == NULL)) {
#ifndef OPENSSL_NO_UI
        /* build a null-terminated list */
        static char *passwds_static[2] = { NULL,NULL };

        passwds = passwds_static;
        if (in == NULL)
            if (EVP_read_pw_string
                (passwd_malloc,!(passed_salt || in_noverify)) != 0)
                goto end;
        passwds[0] = passwd_malloc;
#else
        BIO_printf(bio_err,"password required\n");
        goto end;
#endif
}

我排除了一些解释:

>它可能是为passwds_static引入块范围,但是如果将为类似的目的提供封闭的范围
>它可能是一个通过几个有意义的变换变得没有意义的结构,但那个结构就是since the introduction of OPENSSL_NO_UI.

在这里遗漏了什么吗? (1)有什么好处?这是否用于其他代码库?

谢谢!

解决方法

看了其他类似的地方,I found an explanation
if (1) { /* This is a trick we use to avoid bit rot.
          * at least the "else" part will always be
          * compiled.
          */
#ifdef AF_INET6
    family = AF_INET6;
} else {
#endif
    BIOerr(BIO_F_ACPT_STATE,BIO_R_UNAVAILABLE_IP_FAMILY);
    goto exit_loop;
}

在大多数情况下(包括其CI我猜),OPENSSL_NO_UI没有定义,所以两个分支都被编译.如果其中一个分支机构使用了更改,那么它将被编译器发现,它可以被修复,而无需测试所有的编译时交换机.

大佬总结

以上是大佬教程为你收集整理的这个C语言是什么(if(1))?全部内容,希望文章能够帮你解决这个C语言是什么(if(1))?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: