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,FREEMAIL_FROM, T_FILL_THIS_FORM_SHORT 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!cyclone1.gnilink.net!gnilink.net!wn14feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada Subject: Re: What exactly is a 'record' in Ada 95? From: Jim Rogers References: User-Agent: Xnews/5.04.25 Message-ID: Date: Wed, 08 Sep 2004 12:58:10 GMT NNTP-Posting-Host: 12.73.184.43 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1094648290 12.73.184.43 (Wed, 08 Sep 2004 12:58:10 GMT) NNTP-Posting-Date: Wed, 08 Sep 2004 12:58:10 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:3477 Date: 2004-09-08T12:58:10+00:00 List-Id: 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