<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Array initialization in bsp.c</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/16302/array-initialization-in-bsp-c</link><description>In the file bsp.c (from the SDK11 ble_hrs example) I don&amp;#39;t quite understand the initialization statement: 
 static bsp_button_event_cfg_t m_events_list[BUTTONS_NUMBER] = {{BSP_EVENT_NOTHING, BSP_EVENT_NOTHING}};
 
 bsp_button_event_cfg_t is a struct</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 09 Sep 2016 21:48:54 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/16302/array-initialization-in-bsp-c" /><item><title>RE: Array initialization in bsp.c</title><link>https://devzone.nordicsemi.com/thread/62323?ContentTypeID=1</link><pubDate>Fri, 09 Sep 2016 21:48:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9bf3df6d-a596-4fc1-a525-f958ce64813b</guid><dc:creator>Roger Clark</dc:creator><description>&lt;p&gt;Thanks Tosa.
Hopefully the Nordic guys will read this, and change that file in newer versions of the SDK, to save confusion.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array initialization in bsp.c</title><link>https://devzone.nordicsemi.com/thread/62322?ContentTypeID=1</link><pubDate>Fri, 09 Sep 2016 14:13:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a2b72bd3-54ff-4eb3-a3b2-afaf705a4445</guid><dc:creator>Tosa</dc:creator><description>&lt;p&gt;Thanks Roger. I also think that this &amp;quot;partial&amp;quot; initialization is misleading since the array gets set with the correct values during bsp_init().&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array initialization in bsp.c</title><link>https://devzone.nordicsemi.com/thread/62321?ContentTypeID=1</link><pubDate>Fri, 09 Sep 2016 06:28:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2664aeea-13bd-4dff-9608-89905766b8a9</guid><dc:creator>Roger Clark</dc:creator><description>&lt;p&gt;Admittedly I had to compile this to double check, but...&lt;/p&gt;
&lt;p&gt;But if you compile that code under gcc  it initializes the first element of the array (which is a struct bsp_button_event_cfg_t )&lt;/p&gt;
&lt;p&gt;With values&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;push_event=BSP_EVENT_NOTHING;
long_push_event=BSP_EVENT_NOTHING;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The other property of the struct ( release_event ) does not get initialized, and on gcc its value is zero (which is the same as the enum for BSP_EVENT_NOTHING, but thats partially coincidental.&lt;/p&gt;
&lt;p&gt;Also only the first element of the array gets initialized; which is a bit of a concern, considering BUTTONS_NUMBER is defined in the header file for the board in question, and seems to have possible values of 0 2,3,4 or 8 depending on which board you have.&lt;/p&gt;
&lt;p&gt;I think the only reason this code actually works, is that the enum for BSP_EVENT_NOTHING is defined as 0, and the C compiler initializes static variables to zero which is the same as BSP_EVENT_NOTHING.&lt;/p&gt;
&lt;p&gt;e.g. If you had a board that had 8 buttons, and BSP_EVENT_NOTHING was defined to 1, instead of zero, it would most likely not work.&lt;/p&gt;
&lt;p&gt;I think the code should really be updated to remove the initialization, which  is misleading and incorrect for any board that has more than 1 button.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static bsp_button_event_cfg_t m_events_list[3];
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>