SivaDotRender
SivaDotRender

Reputation: 1651

Simple calculation in GDB yields inconsistent results

I am attempting to debug the following line of code in GDB:

p=((uint32 *) tiff_pixels)+image->columns*i;

p i yeilds 8

p columns yeilds 32

p image->columns*i correctly yields 256

p ((uint32 *) tiff_pixels) yields 0x619000008780

so I expect ((uint32 *) tiff_pixels)+image->columns*i to yield 0x619000008880 but I get 0x619000008b80 instead.

I am probably making some trivial error/assumption here but I cannot seem to figure it out.

Upvotes: 2

Views: 232

Answers (1)

David Schwartz
David Schwartz

Reputation: 182743

You forgot to multiply by the size of each pixel, which is 4 bytes.

p=((uint32 *) tiff_pixels)+image->columns*i;

You've cast tiff_pixels to be a pointer to a uint32. Each uint32 is four bytes. So if you add one to the pointer, it will point to the next uint32, which is four bytes after the first one.

Upvotes: 2

Related Questions