<?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>c++ array initialization on nRF9160</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/83098/c-array-initialization-on-nrf9160</link><description>Hi, 
 I have a C++ array or structure initialization issue that only occurs on nRF9160, but not other devices. 
 I am looking at the possibility of using JEDI in our IoT devices. On other devices, it runs without issues. On nRF9160, I used the mqtt_simple</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 06 Jan 2022 10:41:57 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/83098/c-array-initialization-on-nrf9160" /><item><title>RE: c++ array initialization on nRF9160</title><link>https://devzone.nordicsemi.com/thread/346419?ContentTypeID=1</link><pubDate>Thu, 06 Jan 2022 10:41:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5d7b927b-8cc5-43fd-a5eb-377722b081aa</guid><dc:creator>Didrik Rokhaug</dc:creator><description>&lt;p&gt;Hi, and sorry for the late reply.&lt;/p&gt;
&lt;p&gt;Like I said, I am not familiar enough with the intricacies of C++ to tell you why your attempt didn&amp;#39;t work. I could try to read up on it, though you might get a faster and better reply in the cpp channel on Zephyr&amp;#39;s Discord server.&lt;/p&gt;
&lt;p&gt;You can find a link to join the Discord server here:&amp;nbsp;&lt;a href="https://docs.zephyrproject.org/latest/getting_started/index.html#asking-for-help"&gt;https://docs.zephyrproject.org/latest/getting_started/index.html#asking-for-help&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Didrik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: c++ array initialization on nRF9160</title><link>https://devzone.nordicsemi.com/thread/345140?ContentTypeID=1</link><pubDate>Mon, 27 Dec 2021 15:45:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c9f577c4-ac9a-4151-ba7f-0d5c9883a978</guid><dc:creator>WhiteCloud2</dc:creator><description>&lt;p&gt;Hi, Didrik,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for looking into it and the tip.&lt;/p&gt;
&lt;p&gt;Yes, changing the&amp;nbsp;definition of Inherit&amp;nbsp; indeed leads to correct initialization. It also works for C++17, which I have been using. In addition, if I change the array declaration and do not specify the number of elements, i.e. from [1] to [], then it also works. So the next question is what is wrong, if any, in the original declaration? The issue appears to be a compiler bug since the same program runs correctly compiled using GCC on either a Linux PC or on other IoT devices.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: c++ array initialization on nRF9160</title><link>https://devzone.nordicsemi.com/thread/345114?ContentTypeID=1</link><pubDate>Mon, 27 Dec 2021 13:38:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7fad0446-369a-45da-a5e9-265003461921</guid><dc:creator>Didrik Rokhaug</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I am not familiar enough with C++, and it&amp;#39;s different versions, but if I change the definition of inherit to&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static Inherit inherit[1] = {
        Inherit{{.words = 0xffffffff}}
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and build test_init with C++2a (the default is 11), I get&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;[overlay] 4

FF FF FF FF 

[inherit] 4

FF FF FF FF &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You can change the C++ version to 2a by adding the following config options to your prj.conf file.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_CPLUSPLUS=y
CONFIG_STD_CPP2A=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Didrik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: c++ array initialization on nRF9160</title><link>https://devzone.nordicsemi.com/thread/345025?ContentTypeID=1</link><pubDate>Fri, 24 Dec 2021 17:17:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dd17a531-03e1-4aa9-ab81-b2150eb96cd7</guid><dc:creator>WhiteCloud2</dc:creator><description>&lt;p&gt;I have narrowed it down further to the following example and attached the updated project.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;

struct Data {
    uint32_t words;
};

struct Overlay {
    Data val;
};

struct Inherit : Data {
};

static Overlay overlay[1] = {
        {{.words = 0xffffffff}}
};

static Inherit inherit[1] = {
        {{.words = 0xffffffff}}
};

void print_struct(const char *title, const uint8_t *cbuf, int len)
{
    printf(&amp;quot;[%s] %d\n&amp;quot;, title, len);
    for (int i = 0; i &amp;lt; len; i++) {
        printf(&amp;quot;%02X &amp;quot;, cbuf[i]);
    }
    printf(&amp;quot;\n&amp;quot;);
}

int main() 
{
    print_struct(&amp;quot;overlay&amp;quot;, (const uint8_t *) &amp;amp;overlay[0], sizeof(overlay[0]));   // FF FF FF FF
    print_struct(&amp;quot;inherit&amp;quot;, (const uint8_t *) &amp;amp;inherit[0], sizeof(inherit[0]));   // 00 00 00 00  &amp;lt;--- Incorrect?

    return 0;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/test_5F00_init.zip"&gt;devzone.nordicsemi.com/.../test_5F00_init.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>