sesc360
sesc360

Reputation: 3255

Objective C UInt32 Definition

i found the following statement in code which I not completely understand:

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

The first two lines are clear to me, as these are definitions of UInt32 objects, pixels, and currentPixel. But the line after does not make sense to me honestly. Why is it not:

UInt32 *color = currentPixel

but

UInt32 color = *currentPixel

What is the difference in that?

If I remove the * from currentPixel i get the message: Incompatible pointer to integer conversion initializing 'UInt32' (aka 'unsigned int') with an expression of type 'UInt32 *' (aka 'unsigned int *'); dereference with *

What does dereference with * mean?

Thank you

Upvotes: 1

Views: 3975

Answers (1)

Mornirch
Mornirch

Reputation: 1144

// 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)

pointer like a array, sometime.

there are a tutorial about pointer: http://www.cplusplus.com/doc/tutorial/pointers/

UInt32 isn't a object. it is unsigned long in 32bit machine. unsigned int in 64bit machine.

there are it's define:

#if __LP64__
typedef unsigned int                    UInt32;
typedef signed int                      SInt32;
#else
typedef unsigned long                   UInt32;
typedef signed long                     SInt32;
#endif

Upvotes: 2

Related Questions