Ada for the C or Java Developer AdaCore

Ada For The C Or Java Developer Adacore-Free PDF

  • Date:31 Jul 2020
  • Views:2
  • Downloads:0
  • Pages:68
  • Size:442.57 KB

Share Pdf : Ada For The C Or Java Developer Adacore

Download and Preview : Ada For The C Or Java Developer Adacore

Report CopyRight/DMCA Form For : Ada For The C Or Java Developer Adacore


This work is licensed under a Creative Commons Attribution. NonCommercial ShareAlike 3 0 Unported License,1 Preface 1. 2 Basics 3,3 Compilation Unit Structure 5, 4 Statements Declarations and Control Structures 7. 4 1 Statements and Declarations 7,4 2 Conditions 9. 4 3 Loops 10,5 Type System 13,5 1 Strong Typing 13. 5 2 Language Defined Types 14,5 3 Application Defined Types 14.
5 4 Type Ranges 16, 5 5 Generalized Type Contracts Subtype Predicates 17. 5 6 Attributes 17,5 7 Arrays and Strings 18,5 8 Heterogeneous Data Structures 21. 5 9 Pointers 22,6 Functions and Procedures 25,6 1 General Form 25. 6 2 Overloading 26,6 3 Subprogram Contracts 27,7 Packages 29. 7 1 Declaration Protection 29,7 2 Hierarchical Packages 30.
7 3 Using Entities from Packages 30,8 Classes and Object Oriented Programming 33. 8 1 Primitive Subprograms 33,8 2 Derivation and Dynamic Dispatch 34. 8 3 Constructors and Destructors 37,8 4 Encapsulation 38. 8 5 Abstract Types and Interfaces 38,8 6 Invariants 40. 9 Generics 43,9 1 Generic Subprograms 43,9 2 Generic Packages 44.
9 3 Generic Parameters 45,10 Exceptions 47,10 1 Standard Exceptions 47. 10 2 Custom Exceptions 48,11 Concurrency 49,11 1 Tasks 49. 11 2 Rendezvous 52,11 3 Selective Rendezvous 54,11 4 Protected Objects 55. 12 Low Level Programming 57,12 1 Representation Clauses 57. 12 2 Embedded Assembly Code 58,12 3 Interfacing with C 59.
13 Conclusion 61,14 References 63, Nowadays it seems like talking about programming languages is a bit pass The technical wars of the past decade. have subsided and today we see a variety of high level and well established languages offering functionality that can. meet the needs of any programmer, Python Java C C and Visual Basic are recent examples Indeed these languages make it easier to write code. very quickly are very flexible offer features with highly dynamic behavior and some even allow compilers to deduce. the developer s probable intent, Why then talk about yet another language Well by addressing the general programming market the aforementioned. languages have become poorly suited for working within the domain of high integrity systems In highly reliable. secure and safe applications such as those found in and around airplanes rockets satellites trains and in any device. whose failure could jeopardize human life or critical assets the programming languages used must support the high. standard of software engineering necessary to maintain the integrity of the system. The concept of verification the practice of showing that the system behaves and performs as intended is key in such. environments Verification can be accomplished by some combination of review testing static analysis and formal. proof techniques The increasing reliance on software and increasing complexity of today s systems has made this. task more difficult Technologies and practices that might have been perfectly acceptable ten or fifteen years ago are. insufficient today Thankfully the state of the art in analysis and proof tools and techniques has also advanced. The latest revisions of the Ada language Ada 2005 and Ada 2012 make enhanced software integrity possible From. its inception in the 1980s Ada was designed to meet the requirements of high integrity systems and continues to be. well suited for the implementation of critical embedded or native applications And it has been receiving increased. attention recently Every language revision has enhanced expressiveness in many areas Ada 2012 in particular has. introduced new features for contract based programming that are valuable to any project where verification is part of. the engineering lifecycle Along with these language enhancements Ada compiler and tool technology has also kept. pace with general computing developments over the past few years Ada development environments are available on. a wide range of platforms and are being used for the most demanding applications. It is no secret that we at AdaCore are very enthusiastic about Ada but we will not claim that Ada is always the solution. Ada is no more a silver bullet than any other language In some domains other languages make sense because of. the availability of particular libraries or development frameworks For example C and Java are considered good. choices for desktop programs or applications where a shortened time to market is a major objective Other areas. such as website programming or system administration tend to rely on different formalisms such as scripting and. interpreted languages The key is to select the proper technical approach in terms of the language and tools to meet. the requirements Ada s strength is in areas where reliability is paramount. Learning a new language shouldn t be complicated Programming paradigms have not evolved much since object. oriented programming gained a foothold and the same paradigms are present one way or another in many widely used. languages This document will thus give you an overview of the Ada language using analogies to C and Java these. are the languages you re already likely to know No prior knowledge of Ada is assumed If you are working on an Ada. project now and need more background if you are interested in learning to program in Ada or if you need to perform. an assessment of possible languages to be used for a new development this guide is for you. Ada for the C or Java Developer Release 1 0, This document was prepared by Quentin Ochem with contributions and review from Richard Kenner Albert Lee and. Ben Brosgol,2 Chapter 1 Preface, Ada implements the vast majority of programming concepts that you re accustomed to in C and Java classes.
inheritance templates generics etc Its syntax might seem peculiar though It s not derived from the popular C. style of notation with its ample use of brackets rather it uses a more expository syntax coming from Pascal In many. ways Ada is a simpler language its syntax favors making it easier to conceptualize and read program code rather. than making it faster to write in a cleverly condensed manner For example full words like begin and end are used in. place of curly braces Conditions are written using if then elsif else and end if Ada s assignment operator does not. double as an expression smoothly eliminating any frustration that could be caused by being used where should. All languages provide one or more ways to express comments In Ada two consecutive hyphens mark the start of. a comment that continues to the end of the line This is exactly the same as using for comments in C and Java. There is no equivalent of block comments in Ada use multiple lines instead. Ada compilers are stricter with type and range checking than most C and Java programmers are used to Most. beginning Ada programmers encounter a variety of warnings and error messages when coding more creatively but this. helps detect problems and vulnerabilities at compile time early on in the development cycle In addition dynamic. checks such as array bounds checks provide verification that could not be done at compile time Dynamic checks are. performed at run time similar to what is done in Java. Ada identifiers and reserved words are case insensitive The identifiers VAR var and VaR are treated as the same. likewise begin BEGIN Begin etc Language specific characters such as accents Greek or Russian letters and. Asian alphabets are acceptable to use Identifiers may include letters digits and underscores but must always start. with a letter There are 73 reserved keywords in Ada that may not be used as identifiers and these are. Ada for the C or Java Developer Release 1 0,abort else null select. abs elsif of separate,abstract end or some,accept entry others subtype. access exception out synchronized,aliased exit overriding tagged. all for package task,and function pragma terminate. array generic private then,at goto procedure type,begin if protected until.
body in raise use,case interface range when,constant is record while. declare limited rem with,delay loop renames xor,delta mod requeue. digits new return,do not reverse, Ada is designed to be portable Ada compilers must follow a precisely defined international ISO standard language. specification with clearly documented areas of vendor freedom where the behavior depends on the implementation. It s possible then to write an implementation independent application in Ada and to make sure it will have the same. effect across platforms and compilers, Ada is truly a general purpose multiple paradigm language that allows the programmer to employ or avoid features. like run time contract checking tasking object oriented programming and generics Efficiently programmed Ada is. employed in device drivers interrupt handlers and other low level functions It may be found today in devices with. tight limits on processing speed memory and power consumption But the language is also used for programming. larger interconnected systems running on workstations servers and supercomputers. 4 Chapter 2 Basics,COMPILATION UNIT STRUCTURE, C programming style usually promotes the use of two distinct files header files used to define specifications h.
hxx hpp and implementation files which contain the executable code c cxx cpp However the distinction. between specification and implementation is not enforced by the compiler and may need to be worked around in order. to implement for example inlining or templates, Java compilers expect both the implementation and specification to be in the same java file Yes design patterns. allow using interfaces to separate specification from implementation to a certain extent but this is outside of the scope. of this description, Ada is superficially similar to the C case Ada compilation units are generally split into two parts the specification. and the body However what goes into those files is more predictable for both the compiler and for the programmer. With GNAT compilation units are stored in files with a ads extension for specifications and with a adb extension for. implementations, Without further ado we present the famous Hello World in three languages. with Ada Text IO,use Ada Text IO,procedure Main is. Put Line Hello World,include iostream,using namespace std.
int main int argc const char argv,cout Hello World endl. public class Main,public static void main String argv. System out println Hello World, The first line of Ada we see is the with clause declaring that the unit in this case the Main subprogram will require. the services of the package Ada Text IO This is different from how include works in C in that it does not in a. Ada for the C or Java Developer Release 1 0, logical sense copy paste the code of Ada Text IO into Main The with clause directs the compiler to make the public. interface of the Ada Text IO package visible to code in the unit here Main containing the with clause Note that this. construct does not have a direct analog in Java where the entire CLASSPATH is always accessible Also the name. Main for the main subprogram was chosen for consistency with C and Java style but in Ada the name can be. whatever the programmer chooses, The use clause is the equivalent of using namespace in C or import in Java though it wasn t necessary to use.
import in the Java example above It allows you to omit the full package name when referring to withed units. Without the use clause any reference to Ada Text IO items would have had to be fully qualified with the package. name The Put Line line would then have read,Ada Text IO Put Line Hello World. The word package has different meanings in Ada and Java In Java a package is used as a namespace for classes. In Ada it s often a compilation unit As a result Ada tends to have many more packages than Java Ada package. specifications package specs for short have the following structure. package Package Name is,public declarations,private declarations. end Package Name, The implementation in a package body written in a adb file has the structure. package body Package Name is,implementation,end Package Name. The private reserved word is used to mark the start of the private portion of a package spec By splitting the package. spec into private and public parts it is possible to make an entity available for use while hiding its implementation. For instance a common use is declaring a record Ada s struct whose fields are only visible to its package and not. to the caller This allows the caller to refer to objects of that type but not to change any of its contents directly. The package body contains implementation code and is only accessible to outside code through declarations in the. package spec, An entity declared in the private part of a package in Ada is roughly equivalent to a protected member of a C or.
Java class An entity declared in the body of an Ada package is roughly equivalent to a private member of a C or. Java class,6 Chapter 3 Compilation Unit Structure,STATEMENTS DECLARATIONS AND. CONTROL STRUCTURES,4 1 Statements and Declarations. The following code samples are all equivalent and illustrate the use of comments and working with integer variables. Ada program to declare and modify Integers,procedure Main is. Variable declarations,A B Integer 0,C Integer 100, Ada uses a regular assignment statement for incrementation. project now and need more background if you are interested in learning to program in Ada or if you need to perform an assessment of possible languages to be used for a new development this guide is for you 1 Ada for the C or Java Developer Release 1 0 This document was prepared by Quentin Ochem with contributions and review from Richard Kenner Albert Lee and Ben Brosgol 2 Chapter 1

Related Books