{"id":445,"date":"2011-04-27T13:28:07","date_gmt":"2011-04-27T12:28:07","guid":{"rendered":"http:\/\/www.ozone3d.net\/blogs\/lab\/?p=445"},"modified":"2011-06-08T07:51:10","modified_gmt":"2011-06-08T06:51:10","slug":"offsetof-macro-in-c","status":"publish","type":"post","link":"https:\/\/www.ozone3d.net\/blogs\/lab\/20110427\/offsetof-macro-in-c\/","title":{"rendered":"offsetof macro in C"},"content":{"rendered":"<p>I just discovered this macro available in C: <b>offsetof<\/b>. Here is an simple example:<\/p>\n<pre lang=\"c\">\r\nstruct\r\n{\r\n  char a;\r\n  int b;\r\n  char c;\r\n} example;\r\n\r\nstruct example s1;\r\n\r\nunsigned int offset;\r\noffset = (unsigned int)(&(((example *)(0))->b));\r\n<\/pre>\n<p>Thanks to offsetof (in the header stddef.h), the last line can be rewritten in:<\/p>\n<pre lang=\"c\">\r\nunsigned int offset;\r\noffset = offsetof(example, b);\r\n<\/pre>\n<p><a href=\"http:\/\/www.safercode.com\/blog\/2009\/05\/05\/find-element-offset-structure-c-offsetof.html\">[via]<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just discovered this macro available in C: offsetof. Here is an simple example: struct { char a; int b; char c; } example; struct example s1; unsigned int offset; offset = (unsigned int)(&#038;(((example *)(0))->b)); Thanks to offsetof (in the header stddef.h), the last line can be rewritten in: unsigned int offset; offset = offsetof(example, b); [via]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[112,430,429,637],"class_list":["post-445","post","type-post","status-publish","format-standard","hentry","category-programming","tag-c","tag-macro","tag-offsetof","tag-programming"],"aioseo_notices":[],"views":518,"_links":{"self":[{"href":"https:\/\/www.ozone3d.net\/blogs\/lab\/wp-json\/wp\/v2\/posts\/445","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ozone3d.net\/blogs\/lab\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ozone3d.net\/blogs\/lab\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ozone3d.net\/blogs\/lab\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ozone3d.net\/blogs\/lab\/wp-json\/wp\/v2\/comments?post=445"}],"version-history":[{"count":0,"href":"https:\/\/www.ozone3d.net\/blogs\/lab\/wp-json\/wp\/v2\/posts\/445\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ozone3d.net\/blogs\/lab\/wp-json\/wp\/v2\/media?parent=445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ozone3d.net\/blogs\/lab\/wp-json\/wp\/v2\/categories?post=445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ozone3d.net\/blogs\/lab\/wp-json\/wp\/v2\/tags?post=445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}