From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,789720372441e329 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: matthias_k Newsgroups: comp.lang.ada Subject: Re: What exactly is a 'record' in Ada 95? Date: Wed, 08 Sep 2004 20:05:56 +0200 Organization: T-Online Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.t-online.com 1094666744 02 10277 oMfdXKd6-dtoNdg 040908 18:05:44 X-Complaints-To: usenet-abuse@t-online.de X-ID: XKSEV-ZpQeLW6CCGI+bAhcOSCk3OUR5VrMVXLsPOk6CPUt7yAc8RZV User-Agent: Mozilla Thunderbird 0.5 (X11/20040306) X-Accept-Language: en-us, en In-Reply-To: Xref: g2news1.google.com comp.lang.ada:3500 Date: 2004-09-08T20:05:56+02:00 List-Id: Jim Rogers wrote: > matthias_k wrote in news:chmtr8$6lp$06$1@news.t- > online.com: > > >>So, what is a 'record' in Ada? Do I have to think about it like >>a struct in C? It seems to serve the same purpose. Is 'record' the >>only type modifier? Where are the differences? > > > A record is similar to a struct in C. It is not, however, exactly > the same. Ada records can have a few features not available to C > structs. > > An Ada record can have one or more discriminants which are used to > discriminate between structural representations. The following > example may be helpful. > > type Gender_Type is (Male, Female); > > type Person (Gender : Gender_Type) is record > Name : Name_String; > Age : Natural; > case Gender is > when Male => > Beard_Length : Natural; > when Female => > null; > end case; > end record; > > The first type definition defines an enumeration type. > The second type definition defines a record type with a > discriminant. In this example, all Persons have a name > and age. A person that is Male also has a Beard_Length. > > Discriminant records were introduced in Ada 83. They are > not used much in Ada 95. Ada 95 introduced the concept of > tagged types, which are frequently used instead of > discriminant types. A tagged type is an extensible record > supporting inheritance. > > type Person is tagged record > Name : Name_String; > Age : Natural; > end record; > > type Male is new Person with record > Beard_Length : Natural; > end record; > > Type Male inherits all the attributes of Person and adds > Beard_Length. > > > Records are not the only way to specify a type in Ada. > Ada allows you to specify array types and what other > languages designate as primitive types. > > type Ratings is range 1..10; > > type Real is digits 15; > > type Volt is delta 0.125 range 0.0 .. 255.0; > > type Money is delta 0.02 digits 10; > > type Days is (Sunday, Monday, Tuesday, Wednesday, > Thursday, Friday, Saturday); > > type Daily_Sales is array(Days) of Money; > > Jim Rogers > > Thanks Jim for this detailed answer. Appreciated.