#undef NULL #ifdef __cplusplus # if !defined(__MINGW32__) && !defined(_MSC_VER) # define NULL __null # else # define NULL 0 # endif #else # define NULL ((void*)0) #endif
# define NULL ((void*)0)
char *string = NULL;
#ifndef nil # if __has_feature(cxx_nullptr) # define nil nullptr # else # define nil __DARWIN_NULL # endif #endif
# define nil __DARWIN_NULL就是说nil最终是__DARWIN_NULL的宏定义,__DARWIN_NULL是定义在_types.h中的宏,其定义形式如下:
#ifdef __cplusplus #ifdef __GNUG__ #define __DARWIN_NULL __null #else /* ! __GNUG__ */ #ifdef __LP64__ #define __DARWIN_NULL (0L) #else /* !__LP64__ */ #define __DARWIN_NULL 0 #endif /* __LP64__ */ #endif /* __GNUG__ */ #else /* ! __cplusplus */ #define __DARWIN_NULL ((void *)0) #endif /* __cplusplus */非C++代码的__DARWIN_NULL最终定义形式如下:
#define __DARWIN_NULL ((void *)0)也就是说,nil本质上是:(void *)0
NSString *string = nil; id anyObject = nil;
#ifndef Nil # if __has_feature(cxx_nullptr) # define Nil nullptr # else # define Nil __DARWIN_NULL # endif #endif
Class anyClass = Nil;
@interface NSNull : NSObject <NSCopying, NSSecureCoding> + (NSNull *)null; @end
NSArray *arr = [NSArray arrayWithObjects:@"wang",@"zz",nil];当NSArray里遇到nil时,就说明这个数组对象的元素截止了,即NSArray只关注nil之前的对象,nil之后的对象会被抛弃。比如下面的写法:
NSArray *arr = [NSArray arrayWithObjects:@"wang",@"zz",nil,@"foogry"];这是NSArray中只会保存wang和zz两个字符串,foogry字符串会被抛弃。
NSArray *arr = [NSArray arrayWithObjects:@"wang",@"zz",[NSNull null],@"foogry"];
从前面的介绍可以看出,不管是NULL、nil还是Nil,它们本质上都是一样的,都是(void *)0,只是写法不同。这样做的意义是为了区分不同的数据类型,比如你一看到用到了NULL就知道这是个C指针,看到nil就知道这是个Objective-C对象,看到Nil就知道这是个Class类型的数据。
相对定位父子元素触发mouseover和mouseout事件实验
原文:http://blog.csdn.net/cangkukuaimanle/article/details/18446223