1

私は完全に理解していないコードで次のステートメントを見つけました:

UInt32 *pixels;
UInt32 *currentPixel = pixels;
UInt32 color = *currentPixel;

最初の 2 行は、UInt32 オブジェクト、ピクセル、および currentPixel の定義であるため、私には明らかです。しかし、次の行は正直言って意味がありません。そうでない理由:

UInt32 *color = currentPixel

しかし

UInt32 color = *currentPixel

その違いは何ですか?

currentPixel から * を削除すると、次のメッセージが表示されます。 Incompatible pointer to integer conversion initializing 'UInt32' (aka 'unsigned int') with an expression of type 'UInt32 *' (aka 'unsigned int *'); * による逆参照

* による逆参照とはどういう意味ですか?

ありがとうございました

4

1 に答える 1

2
// 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 ビット マシンでは unsigned int。

それが定義されています:

#if __LP64__
typedef unsigned int                    UInt32;
typedef signed int                      SInt32;
#else
typedef unsigned long                   UInt32;
typedef signed long                     SInt32;
#endif
于 2015-02-26T21:46:18.217 に答える