Author Topic: Which is better for embedded work: C or C++?  (Read 31584 times)

0 Members and 1 Guest are viewing this topic.

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 18031
  • Country: nl
    • NCT Developments
Re: Which is better for embedded work: C or C++?
« Reply #150 on: July 10, 2013, 10:57:37 am »
Thats only true for 8 compilers for 8 bit microcontrollers. Keil used to have web page showing a comparison between their ARM compiler and GCC showing Keil's compiler was way better. Keil had to remove that page because someone did the test again (this time with GCC's optimisation on) and Keil's compiler was nowhere near the results from GCC.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Rufus

  • Super Contributor
  • ***
  • Posts: 2094
Re: Which is better for embedded work: C or C++?
« Reply #151 on: July 10, 2013, 12:12:19 pm »
Just spotted a good quote:

"Rule 1. Never make anything more complex than it needs to be.  OOP is sometimes a hammer looking for a nail when the problem is a screw."?

You continue not to 'get' it.
 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 1947
  • Country: nl
Re: Which is better for embedded work: C or C++?
« Reply #152 on: July 10, 2013, 12:32:23 pm »
Just spotted a good quote:

"Rule 1. Never make anything more complex than it needs to be.  OOP is sometimes a hammer looking for a nail when the problem is a screw."?

You continue not to 'get' it.

Well, at least he partially got it.

Rule 1. Never make anything more complex than it needs to be.

Fixed. The rest was excess fluff that did not add any value.
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 18031
  • Country: nl
    • NCT Developments
Re: Which is better for embedded work: C or C++?
« Reply #153 on: July 10, 2013, 03:31:52 pm »
The problem is that it takes real skills and a lot of thinking to actually make something simple.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Rufus

  • Super Contributor
  • ***
  • Posts: 2094
Re: Which is better for embedded work: C or C++?
« Reply #154 on: July 10, 2013, 04:58:30 pm »
The problem is that it takes real skills and a lot of thinking to actually make something simple.

Complex problems require complex solutions. The answer is to use methodology and tools which help you manage the complexity.

That is why trying to criticise OOP for being too complex is so not getting it.
 

Offline WarSim

  • Frequent Contributor
  • **
  • Posts: 514
Which is better for embedded work: C or C++?
« Reply #155 on: July 11, 2013, 12:59:01 am »
I would like to remind everyone that C and C++ are not separate languages. 
C++ is the abstraction layer of C. 
Originally C++ was only a pre-processor for C compilers. 

C++ generate C compliant code structures for the linker. 
The only thing that changed is the pre-processor and compilation are done with the same tool instead of two steps with two tools. 
It is possible to use a C++ compiler to generate C code if it supports inter-process dumps. 

The discussion is not about which language is better,
The discussion is if the use of abstraction / OO layer is required all the time. 

My answer is no I don't think every programming project requires C++ abstraction every time. 
Of course the C++ abstraction layer is great tool in some cases, for the same reasons it was created in the first place. 
 

Offline cthree

  • Frequent Contributor
  • **
  • Posts: 258
  • Country: ca
Re: Which is better for embedded work: C or C++?
« Reply #156 on: July 11, 2013, 01:14:56 am »
The 40% code size reduction for AVR comes from Atmel in regards to their BitCloud ZigBee stack. They published it in one of their app notes showing the FLASH requirements of BitCloud when compiled with GCC vs IAR. The difference is right about 40%.

ataradov wrote BitCloud, maybe he could elaborate on the differences but I will say that when built for the atmega128rfa1 GCC leaves about 6k flash left for the application vs over 50k when built with IAR. I can't remember the exact numbers but it was ~120k of code vs ~60k. I think it is in an app note but I'll have to dig around to find it.

GCC isn't a great compiler but it is free and open source. Those two things don't necessarily go hand in hand.
« Last Edit: July 11, 2013, 01:18:32 am by cthree »
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 18031
  • Country: nl
    • NCT Developments
Re: Which is better for embedded work: C or C++?
« Reply #157 on: July 11, 2013, 01:52:22 am »
I think I found the appnote but its 16k versus 12k. The difference is usually in the libraries. Where GCC usually comes with standard (full blown) libraries commercial compiler vendors usually provide lightweight libraries. For my projects I use the extremely lightweight C library which comes with mspgcc but it takes a little bit of effort to compile for ARM or other platforms. The bottom line is: with large differences someone probably did something wrong. The amount of development effort being put into GCC dwarfs the amount of effort a commercial compiler vendor can put into their product.
« Last Edit: July 11, 2013, 01:55:54 am by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline cthree

  • Frequent Contributor
  • **
  • Posts: 258
  • Country: ca
Re: Which is better for embedded work: C or C++?
« Reply #158 on: July 11, 2013, 02:42:24 pm »
I think I found the appnote but its 16k versus 12k. The difference is usually in the libraries. Where GCC usually comes with standard (full blown) libraries commercial compiler vendors usually provide lightweight libraries. For my projects I use the extremely lightweight C library which comes with mspgcc but it takes a little bit of effort to compile for ARM or other platforms. The bottom line is: with large differences someone probably did something wrong. The amount of development effort being put into GCC dwarfs the amount of effort a commercial compiler vendor can put into their product.

That isn't exactly true. The amount of work going into GCC is mainly targeted at microprocessor systems, not embedded systems. On the embedded side there is very little work going into it. Hence the large gap in code density. The work going in is multiprocessing, virtualization, security, gpu not cramming as much code as possible into 8k of flash. IAR gets a leg up in this area because while the total effort going in may be less it is going toward things which matter to embedded developers. That is my logic reasoning anyway, not that I have any facts to back it up.

As you say, the standard libraries are not optimized for embedded microcontrollers and it was never designed to build for 8-bit systems or systems without a memory manager.

Another thing which ties the hands of GCC developers is IP and patent licensing. GCC has to work around patented processes, it can't license them like a commercial tool vendor can. Some optimizations may simplest not be available.

I'm not saying GCC is bad or wanky, just not the best tool chain, especially on embedded systems. Even Apple has phased out GCC in favor of LLVM and clang which leaves arm Linux and AVR/arduino as the only significant embedded platforms. Correct me if I'm wrong but GCC is far from optimal on embedded systems, especially 8bit microcontrollers
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 18031
  • Country: nl
    • NCT Developments
Re: Which is better for embedded work: C or C++?
« Reply #159 on: July 11, 2013, 10:25:06 pm »
I'm not saying GCC is bad or wanky, just not the best tool chain, especially on embedded systems. Even Apple has phased out GCC in favor of LLVM and clang which leaves arm Linux and AVR/arduino as the only significant embedded platforms. Correct me if I'm wrong but GCC is far from optimal on embedded systems, especially 8bit microcontrollers
Like I typed before: writing a compiler for convoluted 8 bit platforms like 8051 and PIC is an art in itself. Keil's 8051 compiler really does miracles but for mainstream 16 and 32 bit microcontrollers (68k, H8, MSP430, MIPS, ARM) GCC performs excellent. IMHO what Mojo-chan says about GCC goes for any compiler: you need to know what kind of optimisation is best for your project and use those compiler options. That takes some reading and experimenting. Usually you can get away with -O3 and -Os (with ARM code there is a difference in speed).
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline PuterGeek

  • Regular Contributor
  • *
  • Posts: 88
  • Country: us
    • SolutionsPLUS engineering
Re: Which is better for embedded work: C or C++?
« Reply #160 on: July 12, 2013, 02:08:13 am »
... GCC is mainly targeted at microprocessor systems, not embedded systems.

While the primary target for GCC is Linux systems, those systems are targeting embedded applications more and more. If the target processor is ARM, the performance is pretty good and AVR processors have good support. No other commonly used bare metal processors are supported.

Atmel provides a version of GCC in Atmel Studio and ARM supports the free GNU Tools for ARM Embedded Processors (https://launchpad.net/gcc-arm-embedded). Both include libraries targeted for embedded use.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf