struct - What value will contain_of() return when two different integers are considered in a structure -


consider defined structure t

struct t { int a, b; }; 

if address of b 0x8b3000c , sizeof(int) 4. value container_of() return when invoked

container_of macro in linux kernel code, calculates address of container.

for ewxample, in case

struct t {     int a, b; }; 

applying container_of on address of b yield address of struct t

struct t *pt = container_of(ptr_b, struct t, b); 

where ptr_b hold address of b, &b

normally, won't care physical value got, 0x8b3000c, work identifiers.

as interested in physical, both members int size 4, ignoring padding, pt have (ox8b3000c -4) = ox8b30008

but but, please never make such assumption while coding, struct may padded. use sizeof


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -