Ada 2012 redux

January 14, 2013

Jack Ganssle-January 14, 2013

In September I wrote about the new Ada 2012 standard ("Ada gets a makeover"). That article elicited quite a few responses, and some misinformation. So, I digested some of the discussion into questions, which I sent to the folks at AdaCore. They were kind to reply. Here's that discussion.

Are Ada's run-time libraries generally written in Ada? If not, why is that?

The only compiler I can speak about is GNAT. Yes, for GNAT, the run-time libraries are indeed written in Ada. In the case of GNAT, most of the compiler is also written in Ada. (The rest being the standard GCC technology, written in C.)

In some circles Ada has long held a reputation of being bloated, in terms of size and performance of the generated code. I know there are some profiles, like Ravenscar, that can scale back the size quite a bit. How does the code generated by modern compilers compare to that from, say, C of C++ compilers?

With today's technology, there's no reason why code generated from Ada would be generally slower--or faster--than that of a program doing the same thing written in C or C++. A couple of interesting points are relevant here:

  • The fundamental computation model of Ada is imperative, and most concepts of imperative programming are available with semantics that are very close to those of these other languages. There is no reason why those in Ada would be slower.
  • In the case of GNAT, the code generator is the same, whether you compile for C, C++ or Ada and that's where the bulk of the optimizations are performed. As a result, for the same algorithms, the performance will be the same.
  • One common mistake in comparing the performance of Ada with that of C is to compare Ada with checks enabled and C without checks. Indeed, if you assign a value to a numeric type in Ada, the compiler will generate a check verifying that the value is in range, which takes more time than just doing the assignment. However, we then have two programs that do different things so the difference in performance is reasonable. It's perfectly possible to produce the same performance in Ada by altering the semantics, in this case removing those checks.
  • There are a number of cases where code generated by Ada is actually faster than C or C++ code because the language provides semantics that can be better optimized by the compiler than code that's written manually. Subtype checking is a good example of that.
  • For run-time size, comparing Ada with C++, which offers the same level of capabilities (object orientation, exception, multi-threading, etc), is the most relevant. It shows a comparable run-time footprint. Indeed, for smaller systems, smaller Ada run-times exist: with GNAT, you can go all the way down to no run-time at all.

< Previous
Page 1 of 5
Next >

Loading comments...