打印

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

[复制链接]
2821|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的源码?

使用特权

评论回复
5
mxh0506| | 2012-1-10 20:11 | 只看该作者
这里的NULL其实就是一个预定义常数"0"

使用特权

评论回复
6
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

使用特权

评论回复
7
solo777|  楼主 | 2012-1-10 20:14 | 只看该作者
看来真的是null==null是ture。
第一次发现呀

使用特权

评论回复
8
solo777|  楼主 | 2012-1-10 20:18 | 只看该作者
你这是atomthreads的源码?
李富贵 发表于 2012-1-10 20:11


是!

使用特权

评论回复
9
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

使用特权

评论回复
10
hgjinwei| | 2012-1-10 21:08 | 只看该作者
0 == 0 肯定为真啦。。。

使用特权

评论回复
11
peigang| | 2012-1-11 15:18 | 只看该作者
学习了

使用特权

评论回复
12
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。这种用法在强类型语言中是不允许的。

使用特权

评论回复
13
香水城| | 2012-1-12 08:24 | 只看该作者
本帖最后由 香水城 于 2012-1-12 10:00 编辑

C本来就不是强类型语言,正因为它灵活,所以它强大且具有生命力。

使用特权

评论回复
14
solo777|  楼主 | 2012-1-17 19:10 | 只看该作者
C本来就不是强类型语言,正因为它灵活,所以它强大且具有生命力。
香水城 发表于 2012-1-12 08:24


这句话是什么意思?什么是强类型?

使用特权

评论回复
15
leave99| | 2012-1-18 00:17 | 只看该作者
一向以为NULL就是0

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

83

主题

375

帖子

2

粉丝