{"id":2012,"date":"2014-02-28T10:53:31","date_gmt":"2014-02-28T10:53:31","guid":{"rendered":"http:\/\/blog.bachi.net\/?p=2012"},"modified":"2014-03-03T11:36:15","modified_gmt":"2014-03-03T11:36:15","slug":"c-static-array-initialization","status":"publish","type":"post","link":"https:\/\/blog.bachi.net\/?p=2012","title":{"rendered":"C Designated Initializers"},"content":{"rendered":"<h3>Static Struct Initialization<\/h3>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nstruct student {\r\n    int roll;\r\n    int class;\r\n    char name&#x5B;50];\r\n};\r\n\r\nstudent mark = {\r\n    .name = &quot;Mark&quot;,\r\n    .class  = 10,\r\n    .roll  = 1038\r\n};\r\n<\/pre>\n<p><a href=\"http:\/\/gcc.gnu.org\/onlinedocs\/gcc\/Designated-Inits.html\">GCC: 6.26 Designated Initializers<\/a><br \/>\n<a href=\"http:\/\/gcc.gnu.org\/onlinedocs\/gcc-4.4.1\/gcc\/Designated-Inits.html#Designated-Inits\">GCC 4.4.1: 5.23 Designated Initializers<\/a><br \/>\n<a href=\"http:\/\/linuxprograms.wordpress.com\/2008\/03\/07\/c-structure-initialization-advanced\/\">C: Structure Initialization (Advanced)<\/a><\/p>\n<h3>Static Array Initialization<\/h3>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n#define ADDRESS1 0x01\r\n#define ADDRESS2 0x02\r\n#define ADDRESS3 0x03\r\n#define ADDRESS4 0x04\r\n\r\nconst static uint32_t address_map&#x5B;] = {\r\n    &#x5B;0] = ADDRESS1,\r\n    &#x5B;1] = ADDRESS2,\r\n    &#x5B;2] = ADDRESS3,\r\n    &#x5B;3] = ADDRESS4\r\n};\r\n<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\r\n#define REGISTER_MAP(name, reg) &#x5B;name] = reg\r\n\r\n#define NAME1    0x03\r\n#define NAME2    0x01\r\n#define NAME3    0x02\r\n#define NAME4    0x04\r\n\r\n#define ADDRESS1 0x01\r\n#define ADDRESS2 0x02\r\n#define ADDRESS3 0x03\r\n#define ADDRESS4 0x04\r\n\r\nconst static uint32_t address_map&#x5B;] = {\r\n    REGISTER_MAP(NAME1, ADDRESS1),\r\n    REGISTER_MAP(NAME2, ADDRESS2),\r\n    REGISTER_MAP(NAME3, ADDRESS3),\r\n    REGISTER_MAP(NAME4, ADDRESS4)\r\n};\r\n<\/pre>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/201101\/how-to-initialize-an-array-in-c\">How to initialize an array in C<\/a><br \/>\n<a href=\"http:\/\/publib.boulder.ibm.com\/infocenter\/lnxpcomp\/v8v101\/index.jsp?topic=\/com.ibm.xlcpp8l.doc\/language\/ref\/aryin.htm\">Initialization of arrays<\/a><br \/>\n<a href=\"http:\/\/stupefydeveloper.blogspot.ch\/2008\/10\/c-initializing-arrays.html\">c: initializing arrays<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Static Struct Initialization struct student { int roll; int class; char name&#x5B;50]; }; student mark = { .name = &quot;Mark&quot;, .class = 10, .roll = 1038 }; GCC: 6.26 Designated Initializers GCC 4.4.1: 5.23 Designated Initializers C: Structure Initialization (Advanced) Static Array Initialization #define ADDRESS1 0x01 #define ADDRESS2 0x02 #define ADDRESS3 0x03 #define ADDRESS4 0x04 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2012","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/2012","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2012"}],"version-history":[{"count":3,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/2012\/revisions"}],"predecessor-version":[{"id":2020,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/2012\/revisions\/2020"}],"wp:attachment":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}