不确定标题是否正确,但我相信问题就在那里。 我有这段代码:
FILE_DIRECTORY_INFORMATION *Buffer; Buffer = ExAllocatePoolWithTag (NonPagedPool, 4096, 'arK'); ..<fill in data into the buffer>.. //Values here are: Buffer:0x81490000; NextEntryOffset:0x48 Buffer += Buffer->NextEntryOffset; //Values here are: Buffer:0x81491440; NextEntryOffset:0x0问题是,最后一个代码行执行乘法而不是简单添加。 新的缓冲区值应该是(或者至少我希望它是:) 81490048但是81491440(81490000 + 48 * 48)。 谁能解释我为什么?
PS:我使用Windbg检查了所有值。 使用VS11编译,最后一行代码行真正翻译成imul指令。
not sure if the title is correct but I believe problem is there. I have this piece of code:
FILE_DIRECTORY_INFORMATION *Buffer; Buffer = ExAllocatePoolWithTag (NonPagedPool, 4096, 'arK'); ..<fill in data into the buffer>.. //Values here are: Buffer:0x81490000; NextEntryOffset:0x48 Buffer += Buffer->NextEntryOffset; //Values here are: Buffer:0x81491440; NextEntryOffset:0x0Problem is that instead of simple adding, the last code line performs multiplying. The new Buffer value should be (or at least I would wish it to be:) 81490048 but is 81491440 (81490000+48*48). Can anyone explain me why?
PS: I checked all the values using Windbg. Compiled using VS11, last code line is really translated into imul instruction.
最满意答案
这就是指针算法在C中的工作原理。将“X”添加到指针实际上意味着将指针X的大小添加到起始内存位置。
我想你可能会把一个临时的char *扔回去,但我想不出一个原因。
That's how pointer arithmetic works in C. Adding 'X' to a pointer actually means adding the size of the pointee X times to the starting memory location.
I think you can probably cast to a temporary char * and back, but I can't think of a reason.
更多推荐
发布评论