两个null比较相等,是什么情况?

[复制链接]
4025|14
 楼主| solo777 发表于 2012-1-10 20:01 | 显示全部楼层 |阅读模式
返回ture还是flash

prev_ptr = next_ptr = *tcb_queue_ptr;

if ((next_ptr == NULL)
如果tcb_queue_ptr=null,

那么上面的if,是真,还是假
 楼主| solo777 发表于 2012-1-10 20:04 | 显示全部楼层
本帖最后由 solo777 于 2012-1-10 20:08 编辑

uint8_t tcbEnqueuePriority (ATOM_TCB **tcb_queue_ptr, ATOM_TCB *tcb_ptr)
{
    uint8_t status;
    ATOM_TCB *prev_ptr, *next_ptr;

    /* Parameter check */
    if ((tcb_queue_ptr == NULL) || (tcb_ptr == NULL))
    {
        /* Return error */
        status = ATOM_ERR_PARAM;
    }
    else
    {
        /* Walk the list and enqueue at the end of the TCBs at this priority */
       prev_ptr = next_ptr = *tcb_queue_ptr;
        do
        {
            /* Insert if:
             *   next_ptr = NULL (we're at the head of an empty queue or at the tail)
             *   the next TCB in the list is lower priority than the one we're enqueuing.
             */
            if ((next_ptr == NULL) || (next_ptr->priority > tcb_ptr->priority))
            {
                /* Make this TCB the new listhead */
                if (next_ptr == *tcb_queue_ptr)//这里也是null呀!
                {
                    *tcb_queue_ptr = tcb_ptr;
                    
                    tcb_ptr->prev_tcb = NULL;                    tcb_ptr->next_tcb = next_ptr;
      
                    if (next_ptr)
                        next_ptr->prev_tcb = tcb_ptr;
                }
                /* Insert between two TCBs or at the tail */
                else
                {
                    tcb_ptr->prev_tcb = prev_ptr;
                    tcb_ptr->next_tcb = next_ptr;
                    prev_ptr->next_tcb = tcb_ptr;
                    if (next_ptr)
                        next_ptr->prev_tcb = tcb_ptr;
                }

                /* Quit the loop, we've finished inserting */
                break;
            }
            else
            {
                /* Not inserting here, try the next one */
                prev_ptr = next_ptr;
         
                next_ptr = next_ptr->next_tcb;
      
            }

        }
        while (prev_ptr != NULL);
 楼主| solo777 发表于 2012-1-10 20:05 | 显示全部楼层
本帖最后由 solo777 于 2012-1-10 20:07 编辑

null可以比较吗
李富贵 发表于 2012-1-10 20:11 | 显示全部楼层
你这是atomthreads的源码?
mxh0506 发表于 2012-1-10 20:11 | 显示全部楼层
这里的NULL其实就是一个预定义常数"0"
 楼主| solo777 发表于 2012-1-10 20:13 | 显示全部楼层
在php中有介绍,null==null是ture

下面的代码

#include <stdio.h>

int main(int argc, char *argv[])
{

        char a=NULL, b=NULL;
        if(a==b)
        printf("Hello, world\n");
       
        return 0;
}

这个输出 hello
 楼主| solo777 发表于 2012-1-10 20:14 | 显示全部楼层
看来真的是null==null是ture。
第一次发现呀
 楼主| solo777 发表于 2012-1-10 20:18 | 显示全部楼层
你这是atomthreads的源码?
李富贵 发表于 2012-1-10 20:11


是!
 楼主| solo777 发表于 2012-1-10 20:19 | 显示全部楼层
这里的NULL其实就是一个预定义常数"0"
mxh0506 发表于 2012-1-10 20:11


是呀,

#define _NULL           0       /* 0L if pointer same as long */

但是0==0,这个是等于1,还是等于0呢?

但是目前编译器情况下,turbo c 和tcc都是等于1
hgjinwei 发表于 2012-1-10 21:08 | 显示全部楼层
0 == 0 肯定为真啦。。。
peigang 发表于 2012-1-11 15:18 | 显示全部楼层
学习了
mxh0506 发表于 2012-1-11 23:10 | 显示全部楼层
是呀,

#define _NULL           0       /* 0L if pointer same as long */

但是0==0,这个是等于1,还是等于0呢?

但是目前编译器情况下,turbo c 和tcc都是等于1
solo777 发表于 2012-1-10 20:19

其实这是C语言对数据类型的限制不够严格才造成的混淆. 在概念上, "=="运算结果应该是逻辑类型(boolean,其取值为true, false)。而C语言中的boolean实际上就是某种长度的整型,编译器甚至允许在逻辑判断表达式中直接使用“1”和“0”这样的数值来代替true和false。这种用法在强类型语言中是不允许的。
香水城 发表于 2012-1-12 08:24 | 显示全部楼层
本帖最后由 香水城 于 2012-1-12 10:00 编辑

C本来就不是强类型语言,正因为它灵活,所以它强大且具有生命力。
 楼主| solo777 发表于 2012-1-17 19:10 | 显示全部楼层
C本来就不是强类型语言,正因为它灵活,所以它强大且具有生命力。
香水城 发表于 2012-1-12 08:24


这句话是什么意思?什么是强类型?
leave99 发表于 2012-1-18 00:17 | 显示全部楼层
一向以为NULL就是0
您需要登录后才可以回帖 登录 | 注册

本版积分规则

83

主题

375

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部