<?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>Why can&amp;#39;t you add a new class in Segger ?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/22465/why-can-t-you-add-a-new-class-in-segger</link><description>What hidden settings am I missing this time in the awful Segger studio ? 
 I get an error : 
 
 unknown type name class 
 
 When I compile with this new class called Test.cpp : 
 .cpp file: 
 #include &amp;quot;Test.h&amp;quot;


Test::Test()
{
 
} 
 
 and</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 03 Jun 2017 11:43:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/22465/why-can-t-you-add-a-new-class-in-segger" /><item><title>RE: Why can't you add a new class in Segger ?</title><link>https://devzone.nordicsemi.com/thread/88326?ContentTypeID=1</link><pubDate>Sat, 03 Jun 2017 11:43:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c11678dc-9571-45f3-b24a-bfca8a253c0a</guid><dc:creator>butch</dc:creator><description>&lt;p&gt;The question whether to use C or C++ is subjective, opinionated.  You can mix C and C++, but it takes some learning and work.  The main thing you need to understand is C++ &amp;quot;name mangling&amp;quot; (the two different calling conventions) and when to wrap C code that is being compiled by the C++ compiler in &amp;quot;extern &amp;quot;C&amp;quot; {}&amp;quot; wrapper.  Nordic doesn&amp;#39;t &amp;quot;officially&amp;quot; support C++ but much of their code is C++ compatible.  I use the C++ compiler with the Nordic SDK, but I don&amp;#39;t use all of the SDK, and in a few places I made a few minor hacks to the SDK, and I need to ignore a few warnings from the C++ compiler.  So maybe I get C++&amp;#39;s advantage of OOP, but it comes with the cost of dealing with mixed C/C++.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why can't you add a new class in Segger ?</title><link>https://devzone.nordicsemi.com/thread/88325?ContentTypeID=1</link><pubDate>Fri, 02 Jun 2017 12:19:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0b9a8b0e-5633-45f7-964d-d32a7405ba45</guid><dc:creator>Lola</dc:creator><description>&lt;p&gt;Ok thanks, sorry for asking. I just keep wondering if writing a production code only in C is something people usually do.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why can't you add a new class in Segger ?</title><link>https://devzone.nordicsemi.com/thread/88324?ContentTypeID=1</link><pubDate>Fri, 02 Jun 2017 11:42:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b5146a1c-a151-4cf9-97ec-9dd86f20bae3</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Our SDK does not support C++ beyond the header guards in the drivers/libraries, and as far as I know this will not change in the near future. If you want to use C++, you need to spend the time it takes to convert the project into C++. There are much resources online that can help you solve any issues you could encounter. This is not a Nordic-specific issue, you would have encountered the same issues converting any C project into supporting C++.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why can't you add a new class in Segger ?</title><link>https://devzone.nordicsemi.com/thread/88323?ContentTypeID=1</link><pubDate>Fri, 02 Jun 2017 11:11:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:198d6056-a8ea-42d3-bc84-ae601c3e330e</guid><dc:creator>Lola</dc:creator><description>&lt;p&gt;Thanks a lot, I have actually seen this page and tried it all, nothing helps. My question is, if you want to write a complex embedded application, you probably would like to use C++ to make it more powerful( arn&amp;#39;t you? )  and you will always have C code from the drivers, and the libraries. So at some point you would like to include a c++ file to your code. To do that I did as you suggested, changed main to be cpp , so I can include cpp. Then everyone says you can&amp;#39;t do that. So what CAN I do to use C++ ? :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why can't you add a new class in Segger ?</title><link>https://devzone.nordicsemi.com/thread/88322?ContentTypeID=1</link><pubDate>Fri, 02 Jun 2017 11:08:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:690e52be-4ae6-4061-9244-851fb93b5e86</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Yes, if you have C code in the main.c file, you cannot simply change it to .cpp. See for instance &lt;a href="https://isocpp.org/wiki/faq/mixing-c-and-cpp#call-cpp"&gt;this page&lt;/a&gt; for more information about calling C++ functions from C.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why can't you add a new class in Segger ?</title><link>https://devzone.nordicsemi.com/thread/88321?ContentTypeID=1</link><pubDate>Fri, 02 Jun 2017 11:02:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a4f42b5-170b-458e-aaf8-4f235348ccea</guid><dc:creator>Lola</dc:creator><description>&lt;p&gt;Hi, if I change the main to cpp I get 250 errors, some of them are :&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;#39;-&amp;gt;&amp;#39; cannot appear in a constant-expression
&amp;#39;&amp;amp;&amp;#39; cannot appear in a constant-expression
a cast to a type other than an integral or enumeration type cannot appear in a constant-expression
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;They are coming from C files used by Nordic (drivers and libraries).
The project was an example project from SDK, and I&amp;#39;v added other things to it.&lt;/p&gt;
&lt;p&gt;I asked some people about it on the net, and they said I can&amp;#39;t just mixed C and C++ files, so for example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;main.cpp
#include &amp;quot;flash.h&amp;quot;
int main(void){}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Will produce errors because I include C file in C++ file , where the C might not be properly writen for C++.&lt;/p&gt;
&lt;p&gt;Some of the errors comes from lines like this :&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NRF_GPIOTE_TASKS_OUT_0     = offsetof(NRF_GPIOTE_Type, TASKS_OUT[0]), /**&amp;lt; Out task 0.*/
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why can't you add a new class in Segger ?</title><link>https://devzone.nordicsemi.com/thread/88320?ContentTypeID=1</link><pubDate>Fri, 02 Jun 2017 09:38:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:842fc2c3-e415-4fe9-98a9-eff4a8b1e165</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Could you post the errors? Did you setup the project from scratch or following the SES tutorial blog post?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why can't you add a new class in Segger ?</title><link>https://devzone.nordicsemi.com/thread/88319?ContentTypeID=1</link><pubDate>Thu, 01 Jun 2017 13:26:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9f40992-b7fb-4cb1-bde6-735aac6e8444</guid><dc:creator>Lola</dc:creator><description>&lt;p&gt;Thanks, if i create a new file main.cpp with the exact same content, the project will give 206 errors on compilation, I am not sure anymore how to work with this Segger, all the obvious things I used to just do, here I always encounter a wall.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why can't you add a new class in Segger ?</title><link>https://devzone.nordicsemi.com/thread/88318?ContentTypeID=1</link><pubDate>Thu, 01 Jun 2017 09:11:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c345146-086d-4c7d-949e-cb96b1f685b8</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;If you want the C++ class from Test.h to be used in main, you need to make main a .cpp file, otherwise it will compile using the C compiler.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why can't you add a new class in Segger ?</title><link>https://devzone.nordicsemi.com/thread/88317?ContentTypeID=1</link><pubDate>Thu, 01 Jun 2017 09:01:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c16f1986-debc-47fb-b565-2ddb25e7e4d9</guid><dc:creator>Lola</dc:creator><description>&lt;p&gt;Thanks, I know it should work but Segger on mac is always hard, nothing just works and I guess I have to &amp;quot;enable&amp;quot; something. I have many files, this is one of them. In the &lt;strong&gt;main&lt;/strong&gt; file (the main is &lt;strong&gt;not&lt;/strong&gt; cpp, it&amp;#39;s a &lt;strong&gt;c&lt;/strong&gt; file ) I include this file ( Test.h) . Should the main become cpp also ? will it then work with the C files ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why can't you add a new class in Segger ?</title><link>https://devzone.nordicsemi.com/thread/88316?ContentTypeID=1</link><pubDate>Thu, 01 Jun 2017 08:51:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a3718fd8-b7eb-44bd-818d-79979d66f5d0</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;I tested with your header file and main.cpp, it compile fine. It seems this issue usually is caused by not compiling using C++, or by &lt;a href="https://en.wikipedia.org/wiki/Circular_dependency"&gt;Circular dependency&lt;/a&gt;. Do you include this in main.cpp, or do you have multiple files in your project?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>