comp.lang.ada
 help / color / mirror / Atom feed
* instantiating io for variant records
@ 1989-04-17 18:32 Maureen Cragg
  1989-04-18  1:46 ` Maureen Cragg
  1989-04-19 12:40 ` instantiating io for variant record stt
  0 siblings, 2 replies; 3+ messages in thread
From: Maureen Cragg @ 1989-04-17 18:32 UTC (permalink / raw)


i have a variant record type defined, something like this:

type field_type is (id, date, text);
type record_type(field : field_type);
type rec_ptr is access record_type;
type record_type(field : field_type) is
   record
     previous : rec_ptr := null;
     next     : rec_ptr := null;
     case field is
        when id =>
           id : integer;
        when date =>
           date : calendar.time;
        when text =>
           line : string(1..80);
     end case;
   end record;

for the purpose of storing different types of info in the same record,
as well as varying numbers of the same type(the text is used to store
free-format data, entered via an text editor:can be any number of lines).

so how does one instantiate sequential_io for this record_type? this:

package rec_io is new sequential_io(record_type);

gives the error msg: "generic package/subprogram spec/body requires
                       a constrained type"

adTHANXvance for any suggestions.
the air drummer

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: instantiating io for variant records
  1989-04-17 18:32 instantiating io for variant records Maureen Cragg
@ 1989-04-18  1:46 ` Maureen Cragg
  1989-04-19 12:40 ` instantiating io for variant record stt
  1 sibling, 0 replies; 3+ messages in thread
From: Maureen Cragg @ 1989-04-18  1:46 UTC (permalink / raw)


after compiling this code successfully under dec ada, i finally figured
out that the discriminant needed a default...dec ada is much more forgiving
than adavax:-}

the air drummer

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: instantiating io for variant record
  1989-04-17 18:32 instantiating io for variant records Maureen Cragg
  1989-04-18  1:46 ` Maureen Cragg
@ 1989-04-19 12:40 ` stt
  1 sibling, 0 replies; 3+ messages in thread
From: stt @ 1989-04-19 12:40 UTC (permalink / raw)



Generally, you must provide a default for the discriminant
for records used for direct or sequential I/O.
This allows the body of the generic to declare an object
large enough to hold any instance, to act as a buffer, etc.
Hence make your record:
   type rec(field : fieldtype := fieldtype'first) is record ...

This approach works with most Ada compilers.

Tucker Taft
Intermetrics, Inc.
Cambridge, MA  02138

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1989-04-19 12:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1989-04-17 18:32 instantiating io for variant records Maureen Cragg
1989-04-18  1:46 ` Maureen Cragg
1989-04-19 12:40 ` instantiating io for variant record stt

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