1

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

sesc360
  • 3,155
  • 10
  • 44
  • 86

1 Answers1

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)

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
Mornirch
  • 1,144
  • 9
  • 10
  • 1
    Yeah.. thats what I guessed.. Still I do not understand how an UInt32 can get assigned a pointer. And why I write *currentPixel instead of just currentPixel – sesc360 Feb 26 '15 at 21:48