To start off, here's my code:
Okay so it compiles fine, but running gives meCode:// setting stuff up std::cout.setf(std::ios::hex); std::cout.unsetf(std::ios::dec); int int_size = sizeof(int); int commands = 5; int max_bytes = 3; int byte_array = (int)malloc(int_size*commands*max_bytes); int* pbyte_array = &byte_array; cout << (0x0012FF3C+(int_size*1)) << "\n\n"; for(int i=0x0;i<commands*max_bytes;i+=0x1) { cout << pbyte_array << "\t+\t"; cout << i*int_size << "\t=\t"; cout << pbyte_array+(i*int_size) << "\n"; }
Basically it's adding 16 each time. If I change it toCode:12ff40 0012FF3C + 0 = 0012FF3C 0012FF3C + 4 = 0012FF4C 0012FF3C + 8 = 0012FF5C 0012FF3C + c = 0012FF6C ................. 0012FF3c + 38 = 0013001C
it adds 4 to the output (instead of 1 as it should). I notice if I change pbyte_array declaration toCode:cout << pbyte_array+1
then it works fine (although the hex output becomes lowercase o_O). I have checked the output of int_size and it's 4 as it should be. If I type the address directly into the loop it does the same thing as it does with the changed pbyte_array declaration.Code:int pbyte_array = (int)(&byte_array)
Basically I want a a pointer/address and the addition of an offset.
I'm running Visual C++ 2008
Thanks!
Oh and also I couldn't get arrays to work properly oddly, which is why I created this code in the first place. It kept saying it couldn't convert (int*) to (int).



LinkBack URL
About LinkBacks



