{"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":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"offsetof macro in C\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"JeGX\"\/>\n\t<meta name=\"keywords\" content=\"programming,c,offsetof,macro\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.ozone3d.net\/blogs\/lab\/20110427\/offsetof-macro-in-c\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"JeGX&#039;s Lab | News en vrac \/ WP sandbox\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"offsetof macro in C | JeGX&#039;s Lab\" \/>\n\t\t<meta property=\"og:description\" content=\"offsetof macro in C\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.ozone3d.net\/blogs\/lab\/20110427\/offsetof-macro-in-c\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2011-04-27T12:28:07+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2011-06-08T06:51:10+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"offsetof macro in C | JeGX&#039;s Lab\" \/>\n\t\t<meta name=\"twitter:description\" content=\"offsetof macro in C\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/20110427\\\/offsetof-macro-in-c\\\/#article\",\"name\":\"offsetof macro in C | JeGX's Lab\",\"headline\":\"offsetof macro in C\",\"author\":{\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/author\\\/jegx\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/#person\"},\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/20110427\\\/offsetof-macro-in-c\\\/#articleImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/84ced5670773799817f2f791816e1124fc739962b2fd55c366a685887c8287cd?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"JeGX\"},\"datePublished\":\"2011-04-27T13:28:07+01:00\",\"dateModified\":\"2011-06-08T07:51:10+01:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/20110427\\\/offsetof-macro-in-c\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/20110427\\\/offsetof-macro-in-c\\\/#webpage\"},\"articleSection\":\"Programming, c++, macro, offsetof, Programming\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/20110427\\\/offsetof-macro-in-c\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/category\\\/programming\\\/#listItem\",\"name\":\"Programming\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/category\\\/programming\\\/#listItem\",\"position\":2,\"name\":\"Programming\",\"item\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/category\\\/programming\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/20110427\\\/offsetof-macro-in-c\\\/#listItem\",\"name\":\"offsetof macro in C\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/20110427\\\/offsetof-macro-in-c\\\/#listItem\",\"position\":3,\"name\":\"offsetof macro in C\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/category\\\/programming\\\/#listItem\",\"name\":\"Programming\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/#person\",\"name\":\"JeGX\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/author\\\/jegx\\\/#author\",\"url\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/author\\\/jegx\\\/\",\"name\":\"JeGX\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/20110427\\\/offsetof-macro-in-c\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/84ced5670773799817f2f791816e1124fc739962b2fd55c366a685887c8287cd?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"JeGX\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/20110427\\\/offsetof-macro-in-c\\\/#webpage\",\"url\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/20110427\\\/offsetof-macro-in-c\\\/\",\"name\":\"offsetof macro in C | JeGX's Lab\",\"description\":\"offsetof macro in C\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/20110427\\\/offsetof-macro-in-c\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/author\\\/jegx\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/author\\\/jegx\\\/#author\"},\"datePublished\":\"2011-04-27T13:28:07+01:00\",\"dateModified\":\"2011-06-08T07:51:10+01:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/#website\",\"url\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/\",\"name\":\"JeGX's Lab\",\"alternateName\":\"The Infamous Lab\",\"description\":\"News en vrac \\\/ WP sandbox\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.ozone3d.net\\\/blogs\\\/lab\\\/#person\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"offsetof macro in C | JeGX's Lab","description":"offsetof macro in C","canonical_url":"https:\/\/www.ozone3d.net\/blogs\/lab\/20110427\/offsetof-macro-in-c\/","robots":"max-image-preview:large","keywords":"programming,c,offsetof,macro","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/20110427\/offsetof-macro-in-c\/#article","name":"offsetof macro in C | JeGX's Lab","headline":"offsetof macro in C","author":{"@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/author\/jegx\/#author"},"publisher":{"@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/#person"},"image":{"@type":"ImageObject","@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/20110427\/offsetof-macro-in-c\/#articleImage","url":"https:\/\/secure.gravatar.com\/avatar\/84ced5670773799817f2f791816e1124fc739962b2fd55c366a685887c8287cd?s=96&d=mm&r=g","width":96,"height":96,"caption":"JeGX"},"datePublished":"2011-04-27T13:28:07+01:00","dateModified":"2011-06-08T07:51:10+01:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/20110427\/offsetof-macro-in-c\/#webpage"},"isPartOf":{"@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/20110427\/offsetof-macro-in-c\/#webpage"},"articleSection":"Programming, c++, macro, offsetof, Programming"},{"@type":"BreadcrumbList","@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/20110427\/offsetof-macro-in-c\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.ozone3d.net\/blogs\/lab#listItem","position":1,"name":"Home","item":"https:\/\/www.ozone3d.net\/blogs\/lab","nextItem":{"@type":"ListItem","@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/category\/programming\/#listItem","name":"Programming"}},{"@type":"ListItem","@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/category\/programming\/#listItem","position":2,"name":"Programming","item":"https:\/\/www.ozone3d.net\/blogs\/lab\/category\/programming\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/20110427\/offsetof-macro-in-c\/#listItem","name":"offsetof macro in C"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.ozone3d.net\/blogs\/lab#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/20110427\/offsetof-macro-in-c\/#listItem","position":3,"name":"offsetof macro in C","previousItem":{"@type":"ListItem","@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/category\/programming\/#listItem","name":"Programming"}}]},{"@type":"Person","@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/#person","name":"JeGX"},{"@type":"Person","@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/author\/jegx\/#author","url":"https:\/\/www.ozone3d.net\/blogs\/lab\/author\/jegx\/","name":"JeGX","image":{"@type":"ImageObject","@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/20110427\/offsetof-macro-in-c\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/84ced5670773799817f2f791816e1124fc739962b2fd55c366a685887c8287cd?s=96&d=mm&r=g","width":96,"height":96,"caption":"JeGX"}},{"@type":"WebPage","@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/20110427\/offsetof-macro-in-c\/#webpage","url":"https:\/\/www.ozone3d.net\/blogs\/lab\/20110427\/offsetof-macro-in-c\/","name":"offsetof macro in C | JeGX's Lab","description":"offsetof macro in C","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/#website"},"breadcrumb":{"@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/20110427\/offsetof-macro-in-c\/#breadcrumblist"},"author":{"@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/author\/jegx\/#author"},"creator":{"@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/author\/jegx\/#author"},"datePublished":"2011-04-27T13:28:07+01:00","dateModified":"2011-06-08T07:51:10+01:00"},{"@type":"WebSite","@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/#website","url":"https:\/\/www.ozone3d.net\/blogs\/lab\/","name":"JeGX's Lab","alternateName":"The Infamous Lab","description":"News en vrac \/ WP sandbox","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.ozone3d.net\/blogs\/lab\/#person"}}]},"og:locale":"en_US","og:site_name":"JeGX's Lab | News en vrac \/ WP sandbox","og:type":"article","og:title":"offsetof macro in C | JeGX's Lab","og:description":"offsetof macro in C","og:url":"https:\/\/www.ozone3d.net\/blogs\/lab\/20110427\/offsetof-macro-in-c\/","article:published_time":"2011-04-27T12:28:07+00:00","article:modified_time":"2011-06-08T06:51:10+00:00","twitter:card":"summary","twitter:title":"offsetof macro in C | JeGX's Lab","twitter:description":"offsetof macro in C"},"aioseo_meta_data":{"post_id":"445","title":"offsetof macro in C | #site_title","description":"offsetof macro in C","keywords":[{"label":"programming","value":"programming"},{"label":"c","value":"c"},{"label":"offsetof","value":"offsetof"},{"label":"macro","value":"macro"}],"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-03-08 08:09:21","updated":"2025-11-24 12:21:58","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.ozone3d.net\/blogs\/lab\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.ozone3d.net\/blogs\/lab\/category\/programming\/\" title=\"Programming\">Programming<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\toffsetof macro in C\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.ozone3d.net\/blogs\/lab"},{"label":"Programming","link":"https:\/\/www.ozone3d.net\/blogs\/lab\/category\/programming\/"},{"label":"offsetof macro in C","link":"https:\/\/www.ozone3d.net\/blogs\/lab\/20110427\/offsetof-macro-in-c\/"}],"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}]}}