c++ - VS 2015 Macro Explanation -


we found macro

#define offsetofclass(base, derived) \     ((dword)(dword_ptr)(static_cast(base*)((derived*)8))-8) 

while working on windows kits header resides here

c:\program files (x86)\windows kits\8.1\include\um\shlwapi.h

what macro ?

this macro calculates offset between base , derived pointers.

first takes random address (8) , casts derived*. says "let's random derived starts @ memory address 8".

then static_casts base*. since base base class of derived, resulting base* pointer or not point @ same point in memory (8), depending on it's layout.

then casts result dword_ptr , dword make number out of pointer. subtracts 8 (the initial value used) , gets offset. random number can used instead of 8.

for example if both base , derived empty classes, then:

  • derived * point 8
  • base* point 8
  • the result dword 8
  • 8-8 = 0, offset between pointers 0.

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -