comp.lang.ada
 help / color / mirror / Atom feed
From: matthias_k <nospam@digitalraid.com>
Subject: Re: What exactly is a 'record' in Ada 95?
Date: Wed, 08 Sep 2004 20:05:56 +0200
Date: 2004-09-08T20:05:56+02:00	[thread overview]
Message-ID: <chnhlo$a15$02$1@news.t-online.com> (raw)
In-Reply-To: <ClD%c.328773$OB3.269507@bgtnsc05-news.ops.worldnet.att.net>

Jim Rogers wrote:
> matthias_k <nospam@digitalraid.com> 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.



  reply	other threads:[~2004-09-08 18:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-08 12:27 What exactly is a 'record' in Ada 95? matthias_k
2004-09-08 12:58 ` Jim Rogers
2004-09-08 18:05   ` matthias_k [this message]
2004-09-08 13:12 ` Marc A. Criley
2004-09-08 18:08   ` matthias_k
2004-09-08 13:30 ` Peter Hermann
2004-09-08 18:09   ` matthias_k
2004-09-09 12:06     ` Peter Hermann
2004-09-18  4:14     ` Richard Pennington
2004-09-08 13:40 ` Georg Bauhaus
2004-09-08 18:22 ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox