Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [Ada-tut] Basic program structure and using the compiler
Index -> General Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wtd




PostPosted: Sat Oct 09, 2004 12:44 am   Post subject: [Ada-tut] Basic program structure and using the compiler

Basic Structure

The basic structure of an Ada 95 program is a procedure. The file name should match the name of the procedure, but be all lower case and the file extension should be ".adb".

code:
procedure Hello_World is
begin
   -- code to be executed here
end Hello_World;


This is about as simple as an Ada 95 program gets.

Compiling

The Ada compiler is quite simple to use. To compile the above program we would simply type:

code:
C:\> gnat make hello_world


And since gnat compiles programs to native executables, you can simply run the program with:

code:
C:\> hello_world


A few quick notes

Ada 95 is case-insensitive. The names Hello_World, hello_world, and Hello_world are all identical to the compiler. For the sake of readability it's best to continue using the same version, though. It's just icing on the cake that the compiler doesn't punish you for forgetting to hold the shift key down.

Since Ada is case-insensitive, it's best to separate individual words that make up a variable, module, function, or procedure name with an underscore.

code:
hello_world


Is much more easily read than:

code:
helloworld


Additionally, upcasing the first letter in each word appears to be an Ada tradition, and serves a useful purpose, since it even more clearly delimits the beginning of each word.

code:
Hello_World


Instead of:

code:
hello_world
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: