"Linux Gazette...making Linux just a little more fun!"


Gnat and Linux: C++ and Java Under Fire

By


Quick Index: Newer than Java / Gnat: gcc understands Ada / Features and Compatibility / Installation / Availability and Commercial Support / Java Byte Code and Distributed Processing / Gripes / Recommendations


Long sessions.
Awkward environments.
Convoluted rules.
Missile guidance systems.

This is the computer language that many people know as Ada. Today's Ada looks more like Inprise's Delphi than its caveman ancestor, and soon will produce Java applets that you can drop into your web sites. However, does it stack up against other languages available for Linux?
 


Newer than Java

The new Ada standard is known as Ada 95. Two years younger than Java, this is the first object-oriented programming language to be internationally standardized. This means that all Ada compilers and their libraries should work exactly the same on any operating system, giving Linux programmers an extra level of portability.

C++ is the de facto standard for Linux programming. After all, the kernel itself is written in C. However, C++ is not suitable for all kinds of projects because different computer languages have different strengths and weaknesses. Ada was designed for team development and embedded systems, leading to advantages over C in development time and debugging. An in-depth 1995 study by Stephen F. Zeigler (http://sw-eng.falls-church.va.us/AdaIC/docs/reports/cada/cada_art.html) showed that development in Ada costs about half that of C++. It also suggests that Ada produces "almost 90% fewer bugs for the final customer".

The test bed compiler for Ada 95 was gnat.
 


Gnat: gcc understands Ada

The Ada compiler produced by Ada Core Technologies (ACT), gnat is available for free for Linux. Gnat is also available for other platforms, including Sun Solaris, Silicon Graphics, DEC Alpha and Microsoft Windows.

Gnat was developed closely with gcc, the native C compiler for Linux. Unlike some compilers that translate a program into C and then feed the C program into gcc, gcc has built-in support for the Ada language. Like g++, gnat works with with gcc, allowing it to produce fast, quality executables without any intermediate steps.

This integration gives a lot of flexibility to programmers who want or need to support multiple languages. Gnat has an extensive set of features for trading variables and function calls between Ada and C/C++. It can import C/C++ items into Ada, export Ada items to C/C++. You can also link Ada functions indirectly into Java, using Java's ability to import C++ functions.

Gnat comes with over 140 standard libraries. These include numeric and string libraries, file operations, hash tables and sorts. If you would rather work directly with Linux C libraries, a variety of "binding" libraries exist, available for download from the Public Ada Library or The Home of the Brave Ada Programmers. These include bindings for POSIX (that is, the kernel), X Windows, Motif, TCL and WWW CGI applications.

Although gnat is distributed under the GPL license, gnat and its libraries may be used in commercial applications.
 


Features and Compatibility

Last year I ran some simple time trials on gnat, the Java Development Kit, and gcc.

Language Performance Comparision
(Pentium 90, 10 million iterations, results in CPU Seconds)
 
Java Ada C
JDK 1.0.1  gnat 3.09  gcc 2.7.2.1
Test
Constant assignment  20.68  0.36  0.23
Long Int assignment  20.88  0.35  0.22
Long Int multiply  29.50  0.38  0.23
Array access  24.52  0.64  0.23
Function Calls  15.63  1.07  0.22
Strings Concatenation  19.29  0.35  2.75

Gnat performed well against gcc. Inspite of gnat's extensive run-time error checks, the test programs ran on average only a third slower than gcc. With these checks disabled, you should get performance comparable with C. As an interpreted language, Java ran several times slower than either Ada or C.

The following table presents a summary of some common features, compared with others languages (including Delphi):

 Summary of Common Features
 
C++  Java  Ada  Delphi
 Feature
Objects & Classes  yes  yes  yes  yes
16-bit Characters  NO  yes  yes  yes
Short Circuiting  NO  yes  yes  yes
Overloading  yes  some*  yes  yes  *no infix operators
Inlining  yes  NO  yes  yes
Built-in Multithreading  NO  yes  yes*  yes  *has 2 kinds
Multiple Inheritance  yes  interfaces  NO  NO
Polymorphism  yes  yes  yes  yes
Private fields  yes  yes  yes  yes
Built-in Distributed Processing  NO  NO+  yes*  NO  *requires free add-on 
+not built-in, uses a class
Garbage Collection  NO  yes  yes*  yes  *not implemented by gnat
 

As you can see, Ada holds its own against Java.


Installation

Because gnat is integrated with gcc, the gnat binaries are compiled for a specific version of gcc and will only work with that version. The latest public version from ACT is 3.10p, which has been compiled for gcc 2.7.2.1. If you have this version, the installation program allows you to install gnat directly on your system. This will overwrite your copy of gcc with one that has Ada support enabled.

If you don't have gcc 2.7.2.1, you can specify a separate directory where gnat will install itself and its personal copy of gcc 2.7.2.1. To make gnat available, you have to perform two additional steps:

  1. The installation program creates a shell script containing environment variables that you can copy to your shell startup script (under bash, this is your .profile file). Gnat uses these variables to locate important files.
  2. Include the gnat directory in the front of your path to prevent gnat from using the gcc that came with your Linux distribution. (Only do this when you want to run gnat.)
When I attempted to install gnat on RedHat, I ran into a number of problems. According to ACT, they are aware of the problems of running gnat under RedHat and instructions on how to get it working are found in the gnat chat and comp.lang.ada archives. Nevertheless, ACT says they will be releasing a RedHat 5.1 compatible public version of gnat in the relatively near future.

Once you have the binaries installed, the more adventuresome can recompile gnat for their version gcc:

  1. You need a copy of the gcc sources in order to build a copy of gcc that's compatible with gnat. These should be available with your Linux distribution. The minimum version is 2.7.2.
  2. Download a copy of the gnat sources, which are available for download from the gnat download site and its mirrors.
  3. Recompile gcc and gnat. Make sure you follow gcc's instructions for activating Ada support.
 


Availability and Commercial Support

The compiler sources and executable for the general public are available for free from ftp://cs.nyu.edu/pub/gnat and its mirrors.

Similar to Samba, ACT can provide comprehensive commercial support, but it costs several thousand dollars. The support includes priority bug fixes and the latest version of gnat (compiled against whatever version of gcc you are using). The commercial support is not strictly required for serious projects for the same reason that Samba isn't. Technical assistance is available on the Internet, and since the compiler adheres to the international standard and has been well-tested, the public release is as well-built and reliable as gcc itself. The commercial support is aimed at substantial projects that need high level support, such as projects critical to the success of a business or department.

Gnat comes with extensive documentation in HTML format that you can browse with lynx or Netscape. This includes complete coverage of all of gnat's unique features and options. Unfortunately, no tutorial for Ada is included.
 


Java Byte Code and Distributed Processing

In the past year, ACT announced that their next release of gnat would be able to produce not only executable programs but Java executables (called "byte code") as well. A gnat program will be able to run on any Java interpreter, such as web site applets running under a Java-enabled browser. This gives Linux web programmers an alternative to using the Java.

ACT also provides a free gnat add-on called "Glade", which enables Ada 95's built-in distributed processing support. Programs using Glade can work with each other transparently over a network.

 


Gripes

I came across a few problems while working with gnat.

When testing gnat, I found a minor problem related to the normalize_scalers pragma. This is a compiler directive that helps to detect variables used before they are initialized. The directive worked fine except in a package containing object definitions. All other language features I tested appeared to work properly under Linux, including multitasking.

Gnat's executables can be several times the size of a gcc executable. Gnat provides compiler directives to reduce a program's size, but if a small footprint is an important issue, you may want to avoid gnat.

Gnat also lacks an IDE, but this is a common problem for Linux languages.

My biggest complaint isn't with the language: it's ACT's uneven customer support. Although I've always received prompt replies from ACT, they are not always courteous or helpful, and I've often been more frustrated than enlightened.

Once I went to my local photocopy shop to make copies of the gnat manual, and they refused because the manuals contain a copyright notice. I emailed ACT and they were quick to respond that the copyright notice would be changed in the next edition. It's been over a year since they updated their FTP site, and I'm still waiting to see this simple change.

On another occasion, my software company was investigating gnat's suitability as a development platform for Linux. As far as we knew, ACT could have been run out of Robert Dewar's basement. We wanted to know that there would be future releases of gnat before we committed ourselves to developing a software base and suffer the stigma of programming in Ada. At first we were told we shouldn't consider developing in gnat unless we had their commercial suppport. Then we were told that they wouldn't provide commerical support for a fledgling company like ourselves. If ACT would have given us a straight answer on the commercial support, told us that we would still be supported on a non-priority basis, and wished us luck on our future endevours, we would have been more than happy. Instead, we felt that they had been dishonest with us and then told that we were dirt when we had gone out on a limb to consider gnat in the first place.

No company should be rude or disrespectful to its clients. They deserve straight-forward answers, timely fixes, and a "please" and "thank you" now and then to show their interest is appreciated.
 


Recommendations

Without a doubt, gnat holds its own against other Linux development tools. I would recommend gnat and Ada for the following: Also, anybody doing Java development for Linux should investigate the next release of gnat.

Robert Dewar, the head of ACT, assured me that "ACT is committed to providing high quality Ada 95 products for Linux. We have a number of serious Ada users using Linux today, and we intend to continue to serve the Linux market for such users."

When speaking of Linux's exponential growth over the last two years, Mr. Dewar was quick to point out that the gnat Linux market is currently small. ACT is not interested in promoting the Ada 95 standard. They would rather spend their time improving their products and selling them to the existing Ada markets. That the Linux community has largely overlooked gnat is not surprising.

The difference between a successful project and a failure can often hinge upon choosing the right development tool for the job, and gnat has a lot to offer. Gnat brings a versatile development environment to Linux, an efficient compiler and a rich set of development tools, and that is something the Linux community cannot ignore. Whether or not gnat has a bright future in Linux is anybody's guess, but it would be a shame if a high quality piece of free software should be overlooked. This is a lesson that all Linux enthusiasts have learned very well.
 


Resources

Web Sites

Ada Core Technologies (ACT): http://www.gnat.com
Ada Information Clearinghouse (AIC): http://sw-eng.falls-church.va.us/
Gnat FTP Site: ftp://cs.nyu.edu/pub/gnat
Home of the Brave Ada Programmers (HBAP): http://www.adahome.com
Public Ada Archive (PAL): http://www.wustl.edu
Samba: http://samba.anu.edu.au/samba/

Books

Professional Java Fundamentals. Cohen, Shy et al. Wrox Press, 1996.
Programming in Ada 95. Barnes, John. Addison Wesley, 1996.
C++ for Professional Programmers. Blaha, Stephen. Int'l Thomson Computer Press, 1995.
 


Copyright © 1998, Ken O. Burtch
Published in Issue 33 of Linux Gazette, October 1998


[ TABLE OF CONTENTS ] [ FRONT PAGE ]  Back  Next