<?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>Can you make some small changes for C++ compatibility.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/42803/can-you-make-some-small-changes-for-c-compatibility</link><description>I had to modify the 0.10 mesh / rf sdk&amp;#39;s to integrate them into a C++ environment and have now to do the same again with the latest SDK&amp;#39;s due to some coding issues in the supplied FW 
 All of our code is written in C++ and my mesh application code also</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 29 Jan 2019 09:33:59 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/42803/can-you-make-some-small-changes-for-c-compatibility" /><item><title>RE: Can you make some small changes for C++ compatibility.</title><link>https://devzone.nordicsemi.com/thread/168402?ContentTypeID=1</link><pubDate>Tue, 29 Jan 2019 09:33:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8221ebe4-9b2a-431b-b8e7-ddaf26923970</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It appears variable length arrays were removed in nRF5 SDK for Mesh v3.0.0, and so we consider this issue to be already fixed.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can you make some small changes for C++ compatibility.</title><link>https://devzone.nordicsemi.com/thread/168310?ContentTypeID=1</link><pubDate>Mon, 28 Jan 2019 16:36:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:502708ea-69c6-4771-b759-455c820d1dee</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thank you for the detailed descriptions.&lt;/p&gt;
&lt;p&gt;I have notified our Mesh team and registered the request in our internal issue tracker.&lt;/p&gt;
&lt;p&gt;For now you must manually do the required changes, but hopefully this is something we can fix for future releases.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can you make some small changes for C++ compatibility.</title><link>https://devzone.nordicsemi.com/thread/167190?ContentTypeID=1</link><pubDate>Tue, 22 Jan 2019 18:18:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:136ad100-16b5-4532-8695-42e033409d87</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;My 2 cents to this. &amp;nbsp;Do not use __attribute((packed)). &amp;nbsp;it is GCC extension. &amp;nbsp;The C language has #pragma pack(x) since the beginning of the C language. &amp;nbsp;Microsoft added the extension #pragma pack(push,x) back in the 80s. &amp;nbsp;It is now a pseudo standard supported by all compilers from VCC to OSX Clang and GCC of course and fully compatible with C++. &amp;nbsp;So the structure should be rewritten as:&lt;/p&gt;
&lt;p&gt;&lt;span&gt;/** BLE Service data packets. */&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;#pragma pack(push, 1)&lt;br /&gt;&lt;span&gt;typedef struct&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;uint16_t uuid; /**&amp;lt; UUID field. */&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;uint8_t *data; /**&amp;lt; Service data field. */&lt;/span&gt;&lt;br /&gt;&lt;span&gt;} ble_ad_data_service_data_t;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;#pragma pack(pop)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;if this&amp;nbsp;&lt;/span&gt;structure is meant to be variable length it should be&lt;/p&gt;
&lt;p&gt;&lt;span&gt;/** BLE Service data packets. */&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;#pragma pack(push, 1)&lt;br /&gt;&lt;span&gt;typedef struct&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;uint16_t uuid; /**&amp;lt; UUID field. */&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;uint8_t data[1]; /**&amp;lt; Service data field. */&lt;/span&gt;&lt;br /&gt;&lt;span&gt;} ble_ad_data_service_data_t;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;#pragma pack(pop)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;Also this kind of macro is consider as bad programming practice, please remove as well.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define NRF_SECTION_SET_DEF(_name, _type, _count)                                                   \ 
/*lint -save -emacro(14, MACRO_REPEAT_FOR*)  */                                                     \ 
MACRO_REPEAT_FOR(_count, NRF_SECTION_DEF_, _name, _type)                                            \ 
static nrf_section_t const CONCAT_2(_name, _array)[] =                                              \ 
{                                                                                                   \ 
    MACRO_REPEAT_FOR(_count, NRF_SECTION_SET_DEF_, _name)                                           \ 
};                                                                                                  \ 
/*lint -restore */                                                                                  \ 
static nrf_section_set_t const _name =                                                              \ 
{                                                                                                   \ 
    .p_first   = CONCAT_2(_name, _array),                                                           \ 
    .p_last    = CONCAT_2(_name, _array) + ARRAY_SIZE(CONCAT_2(_name, _array)),                     \ 
    .item_size = sizeof(_type),                                                                     \ 
} 
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can you make some small changes for C++ compatibility.</title><link>https://devzone.nordicsemi.com/thread/167146?ContentTypeID=1</link><pubDate>Tue, 22 Jan 2019 14:42:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5cb97500-5ee3-42ff-a964-de7b3f588ecf</guid><dc:creator>Phil Young</dc:creator><description>&lt;p&gt;The use of extern &amp;quot;C&amp;quot; simply tells the compiler not to decorate the names of the functions so that the linker can recognize them, the default for C++ is that all function names are decorated with the types which would prevent linking the files.&lt;/p&gt;
&lt;p&gt;extern &amp;quot;C&amp;quot; is essential but insufficient since there are many instances of incomplete type definitions in the function parameters, what this actually means is that C allows for the last parameter to a function to be an un-dimensioned array, which ultimately gets passed as a pointer.&lt;/p&gt;
&lt;p&gt;C++ does not allow for this and sees it as an incomplete type definition, GCC allows it but the ARM compilers do not.&lt;/p&gt;
&lt;p&gt;There is a switch that can be used with ARMCC, --gnu, to make it work in GCC compatible mode which enables support for this mode, but in doing so it defines __GNU_C as well as __CC_ARM_&lt;/p&gt;
&lt;p&gt;in this mode the code will not compile using ARM compilers without editing the source since there are places in the code, particularly in the error logging, where having both of these defined results in incompatible redefinition of macros.&lt;/p&gt;
&lt;p&gt;in summary there are 2 problems.&lt;/p&gt;
&lt;p&gt;1. The use of arrays of undefined length it bad practice, that&amp;#39;s why it was not allowed in C++, arrays are always passed by reference so a pointer is the preferred manner of passing arrays in both C and C++&lt;/p&gt;
&lt;p&gt;2. The assumption that &lt;span&gt;__CC_ARM_&amp;nbsp;&lt;/span&gt;&lt;span&gt;and&amp;nbsp;__GNU_C&amp;nbsp;are mutually exclusive is not valid, in GCC&amp;nbsp;__CC_ARM_ would never be defined, but in ARMCC they will both be defined when using --gnu&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;both of these would be trivial for Nordic to fix and would not affect the generated code in GCC or ARMCC, but would avoid the need to edit the nordic SDK when building a C++ application with ARMs compilers&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;for example&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;/** BLE Service data packets. */&lt;br /&gt;typedef struct __attribute((packed))&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp;uint16_t uuid; /**&amp;lt; UUID field. */&lt;br /&gt;&amp;nbsp; &amp;nbsp;uint8_t data[]; /**&amp;lt; Service data field. */&lt;br /&gt;} ble_ad_data_service_data_t;&lt;/p&gt;
&lt;p&gt;..\..\..\..\mesh\core\include\packet.h(142): error:&amp;nbsp; #70: incomplete type is not allowed&lt;/p&gt;
&lt;p&gt;it would have been better to define it as&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;/** BLE Service data packets. */&lt;/span&gt;&lt;br /&gt;&lt;span&gt;typedef struct __attribute((packed))&lt;/span&gt;&lt;br /&gt;&lt;span&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;uint16_t uuid; /**&amp;lt; UUID field. */&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;uint8_t *data; /**&amp;lt; Service data field. */&lt;/span&gt;&lt;br /&gt;&lt;span&gt;} ble_ad_data_service_data_t;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;this has an identical meaning and is compatible with all compilers in both C and C++ modes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can you make some small changes for C++ compatibility.</title><link>https://devzone.nordicsemi.com/thread/167081?ContentTypeID=1</link><pubDate>Tue, 22 Jan 2019 12:32:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b8b328dd-ab38-4f38-99a5-fee320884b58</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I am trying to understand the issue here. Doesn&amp;#39;t the use of &amp;#39;extern &amp;quot;C&amp;quot;&amp;#39; throughout the SDK let you build the SDK using the C compiler still using the APIs from C++? Or can it not be bridged because of certain function headers? (Can you show me an example taken from the SDK of a function that is problematic?)&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can you make some small changes for C++ compatibility.</title><link>https://devzone.nordicsemi.com/thread/166786?ContentTypeID=1</link><pubDate>Mon, 21 Jan 2019 10:36:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8df8bfb5-eb3a-4f39-8242-1a29252c63eb</guid><dc:creator>Phil Young</dc:creator><description>&lt;p&gt;Thanks, interesting reading but they have not addressed any of the issues at Nordic.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not asking them to write it in C++, simply to avoid using constructs that do not compile with the ISO/ANSI C++ compiler modes.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve written all my embedded code in &amp;quot;C++&amp;quot; for over 20 years and can&amp;#39;t understand why anybody would choose to start a new development in &amp;quot;C&amp;quot;, but for me it&amp;#39;s a bigger issue since I instantiate hundreds of instances of my code in a simulation environment for system level modelling and C++ provides the encapsulation to do that easily and efficiently ( and also produces significantly more efficient object code ).&lt;/p&gt;
&lt;p&gt;The Nordic code is totally incompatible with this technique as it is not possible when using any globals as they cannot be distinguished between multiple instantiations of the device an a model.&lt;/p&gt;
&lt;p&gt;one reason for the increased efficiency of C++ is that writing object oriented code makes you group data into objects that are related and operated on by the same functions thereby providing much better localization of data which greatly simplifies effective address calculation, i.e. the compiler gets to use a single pointer ( this,&amp;nbsp; generally R0 ) with short immediate offsets for accessing data a lot more often and&amp;nbsp; that reduces code size and increases execution efficiency significantly.&lt;/p&gt;
&lt;p&gt;Look at any compiled code and the bulk of the instructions are for effective address computation when data is too far apart to be accessed in this manner.&lt;/p&gt;
&lt;p&gt;Frankly the structure of the data in the Nordic code is really badly managed and inefficient but I can live with that provided I can write my code in C++.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can you make some small changes for C++ compatibility.</title><link>https://devzone.nordicsemi.com/thread/166774?ContentTypeID=1</link><pubDate>Mon, 21 Jan 2019 10:18:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:af08e45d-0b78-40c7-9ba7-cd4ed5eb7520</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;Have you seen this thread:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/39234/why-isn-t-the-sdk-written-in-c"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/39234/why-isn-t-the-sdk-written-in-c&lt;/a&gt;&amp;nbsp;?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>