{"id":1592,"date":"2024-12-05T12:43:45","date_gmt":"2024-12-05T12:43:45","guid":{"rendered":"https:\/\/ibex.tech\/c\/?p=1592"},"modified":"2024-12-05T12:50:47","modified_gmt":"2024-12-05T12:50:47","slug":"__attribute__-examples","status":"publish","type":"post","link":"https:\/\/ibex.tech\/c\/compilers\/gcc-compiler\/attribute\/__attribute__-examples","title":{"rendered":"__attribute__ examples"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Do not optimise the contents of a function<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>__attribute__((optimize(0))) void MyFunction()\n{\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Remove the in and out code for a function<\/h4>\n\n\n\n<p>The compiler does not generate prologue and epilogue sequences for functions with: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>__attribute__((naked)) void MyFunction()\n{\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Avoiding Padding<\/h4>\n\n\n\n<p>You can used the packed variable attribute. For example in the following code, type c_t will have a size of 3 bytes and there will be no wasted space between a and b:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>typedef struct\n{\n  unsigned char a&#91;1];\n} __attribute__ ((packed)) a_t;\n\ntypedef struct\n{\n  unsigned char b&#91;2];\n} __attribute__ ((packed)) b_t;\n\ntypedef struct\n{\n  a_t a;\n  b_t b;\n} __attribute__ ((packed)) c_t;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Do not optimise the contents of a function Remove the in and out code for a function The compiler does not generate prologue and epilogue sequences for functions with: Avoiding Padding You can used the packed variable attribute. For example in the following code, type c_t will have a size of 3 bytes and there [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[121],"tags":[],"class_list":["post-1592","post","type-post","status-publish","format-standard","hentry","category-attribute"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts\/1592","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/comments?post=1592"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts\/1592\/revisions"}],"predecessor-version":[{"id":1594,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/posts\/1592\/revisions\/1594"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/media?parent=1592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/categories?post=1592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/c\/wp-json\/wp\/v2\/tags?post=1592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}