So I'm trying to figure out if I'm dealing with memory correctly by printing out pointer values...I can't find gdb for windows...yes, tried mingw but there was no gdb.exe in it.
Code:
fprintf(stderr, "Allocating %d bytes for %d items, Table.\n", (sizeof(PTR)*storageSize), storageSize);
tbl->Items = (struct TableItem**)malloc(sizeof(PTR)*storageSize);
fprintf(stderr, "Items: %p to %p\n", tbl->Items, tbl->Items + (sizeof(PTR)*storageSize));
for (count=0; count<storageSize; count++)
{
tbl->Items[count] = NULL;
fprintf(stderr, "Item %d, byte %p to %p\n", count, &tbl->Items[count], (&tbl->Items[count])+(sizeof(PTR)));
I'm defining PTR as a long.
This is the output I'm getting...
Allocating 8 bytes. struct Table.
Allocating 40 bytes for 10 items, Table.
Items: 003D1138 to 003D11D8
Item 0, byte 003D1138 to 003D1148
Item 1, byte 003D113C to 003D114C
Item 2, byte 003D1140 to 003D1150
Item 3, byte 003D1144 to 003D1154
Item 4, byte 003D1148 to 003D1158
Item 5, byte 003D114C to 003D115C
Item 6, byte 003D1150 to 003D1160
Item 7, byte 003D1154 to 003D1164
Item 8, byte 003D1158 to 003D1168
Item 9, byte 003D115C to 003D116C
I expected the last memory location to be the same as the last location allocated for my array's space but it was not. I also expected the end of Item 0 to be the beginning of Item 1, but that wasn't the case either. I checked the sizeof(long) vs sizeof(struct TableItem*) and they were the same.
What am I doing wrong???