Atmel Studio/Microchip Studio (use C++?)

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all,

 

I was at some time in the past a user of Atmel Studio 6, I am now using version 7.

Back then I remember reading that it was unadvisable to use C++ to instead use C for safer code.

The actual reasons were not so clear so to be safe I stuck to plain old C. However I would like to use C++ if posible.

My question is, Is there anyone is using version 7 with C++ without any problem? Or are there problems.

 

Many thanks.

 

Stephen.

Last Edited: Sat. Jun 18, 2022 - 12:03 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bukirwa wrote:
However I would like to use C++ if posible.

Go ahead. I don't think you'll find any problems with using C++ in Atmel Microchip Studio.

“Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?” - Brian W. Kernighan
“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” - Antoine de Saint-Exupery

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok Heisen, Thanks very much for that assurance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't think you'll find any problems with using C++

Well, not beyond the usual "by default there is no libg++ nor stl support."  (For some people, that's nearly the same as "doesnt' support C++.  For example, there's no "new")

 

Arduino is an example of using C++ with essentially the same compilers as MS7, to good effect.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Westfw, no new?  So no classes otherwise how do you instatiate an instance of a class?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Westfw, no new?  So no classes otherwise how do you instatiate an instance of a class?

Neither local nor global instances of a class require new();
 

hwSerialClass Serial1(USART0);

int main() {
  hwSerialClass Serial2(USART1);
}

Or, you can implement new using malloc()...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

westfw wrote:
Or, you can implement new using malloc()...
similar for a binned heap

Micro Digital Announces eheap Enhancements

[beginning of fifth paragraph]

Integral block pools have been added to greatly improve speed and efficiency of small-block allocations for object-oriented languages such as C++.

...

due to eheap - A new embedded heap manager - Embedded.com by Jack Ganssle

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I use C++ in Studio 7. I don't use dynamic instantiation but if I wanted to then I'd do the trivial thing mentioned in the sticky at the top of the compilers forum to map new to malloc​​​​​​. I accept the fact that there's no STL but I don't really want the (mainly) dynamically growing constructs (string, vector, etc) it delivers anyway as they are not appropriate to a small RAM micro anyway. If I really missed STL I would Google "avr Andy brown STL" which not only finds his but also a thread in the Arduino fora that offers alternatives to Andy Brown's version.

 

EDIT this is the sticky How-To for C++:

 

https://www.avrfreaks.net/forum/avr-c-micro-how

Last Edited: Sat. Jun 18, 2022 - 12:05 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Thanks all for your response about new'ing classes, I guess I should have generalised the question to be any object that I want to instatiate, however the responses indirectly address this too. So I now feel confident enough to trust C++ on all new code.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bukirwa wrote:
So I now feel confident enough to trust C++ on all new code.
Quote by Bjarne Stroustrup: “C makes it easy to shoot yourself in the foot; ...”

Jack Ganssle's "Reason #8" on why embedded software projects run into trouble | AVR Freaks

 

P.S.

U&S (USA JSF)

Even with an excellent process though huge application(s) :

Kendall: Current F-35 Block 4 Issues Reminiscent of Earlier JSF Problems - Air Force Magazine

so, consider C++20 modules (versus the #include hairball)

C++20 Serves Up Intriguing Embedded Features | Electronic Design

though C++11 is likely good enough for an AVR.

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No problem. Go ahead. Some old threads like this may help you in this regard.

 

https://www.avrfreaks.net/forum/...

 

And if you ever wish to make a PCB of your project, this is a good write-up for you: https://pcbtracks.com/how-to-man...