Objective C UInt32 定义
Objective C UInt32 Definition
我在代码中发现了以下我不完全理解的语句:
UInt32 *pixels;
UInt32 *currentPixel = pixels;
UInt32 color = *currentPixel;
前两行我很清楚,因为它们是 UInt32 对象、像素和 currentPixel 的定义。
但老实说,之后的那一行对我来说没有意义。
为什么不是:
UInt32 *color = currentPixel
但是
UInt32 color = *currentPixel
这有什么区别?
如果我从 currentPixel 中删除 *,我会收到消息:
指向整数转换的指针不兼容,用 'UInt32 *'(又名 'unsigned int *')类型的表达式初始化 'UInt32'(又名 'unsigned int');使用 *
取消引用
取消引用 * 是什么意思?
谢谢
// alloc height * width * 32 bit memory. pixels is first address.
UInt32 *pixels = (UInt32 *) calloc(height * width, sizeof(UInt32));
// you can do like this
UInt32 color = pixels[3]
// or like this, they are equal.
UInt32 color = *(pixels + 3)
有时像数组一样的指针。
有关于指针的教程:
http://www.cplusplus.com/doc/tutorial/pointers/
UInt32 不是对象。
它在 32 位机器上是 unsigned long。
64 位机器中的无符号整数。
有它的定义:
#if __LP64__
typedef unsigned int UInt32;
typedef signed int SInt32;
#else
typedef unsigned long UInt32;
typedef signed long SInt32;
#endif
我在代码中发现了以下我不完全理解的语句:
UInt32 *pixels;
UInt32 *currentPixel = pixels;
UInt32 color = *currentPixel;
前两行我很清楚,因为它们是 UInt32 对象、像素和 currentPixel 的定义。 但老实说,之后的那一行对我来说没有意义。 为什么不是:
UInt32 *color = currentPixel
但是
UInt32 color = *currentPixel
这有什么区别?
如果我从 currentPixel 中删除 *,我会收到消息: 指向整数转换的指针不兼容,用 'UInt32 *'(又名 'unsigned int *')类型的表达式初始化 'UInt32'(又名 'unsigned int');使用 *
取消引用取消引用 * 是什么意思?
谢谢
// alloc height * width * 32 bit memory. pixels is first address.
UInt32 *pixels = (UInt32 *) calloc(height * width, sizeof(UInt32));
// you can do like this
UInt32 color = pixels[3]
// or like this, they are equal.
UInt32 color = *(pixels + 3)
有时像数组一样的指针。
有关于指针的教程: http://www.cplusplus.com/doc/tutorial/pointers/
UInt32 不是对象。 它在 32 位机器上是 unsigned long。 64 位机器中的无符号整数。
有它的定义:
#if __LP64__
typedef unsigned int UInt32;
typedef signed int SInt32;
#else
typedef unsigned long UInt32;
typedef signed long SInt32;
#endif