* differed private declarations (Feature/Bug)
@ 1988-01-23 18:13 Scott Moody
0 siblings, 0 replies; only message in thread
From: Scott Moody @ 1988-01-23 18:13 UTC (permalink / raw)
I was fighting a compiler bug yesterday which I thought interesting,
and didn't even know it was possible in ada.
Try:
-------------------------------------------------
package test_private is
type handle is limited private;
type fruit is (apple,orange);
procedure create_fruit(kind:fruit; result: OUT handle);
private
type handle_record(kind:fruit);
type handle is access handle;
---
-- Differ the actual definition of handle_record until
-- body of package (say this in Ada Rational)
--
end test_private;
package body test_private is
type handle_record(kind:fruit) is
record
field1:integer;
case kind is
when apple => color:integer;
when orange => skin_thickness:integer;
where_from :string(1..100);
end case;
end record;
procedure create_fruit(kind:fruit; result: OUT handle) is
r : handle;
begin
r := new handle_record(kind);
case kind is
when apple => r.color:= 101;
when orange => r.skin_thickness:= 11;
end case;
return r;
end create_fruit;
end test_private;
-------------------------------------------------
It turns out that if the private type is a pointer (access) variable
then the definition of what it points to can be differed until
the body of the package.
Unfortunately the compiler decided that every "new handle_record(kind)"
translated into fruit'first instead of the one desired.
(Actually the enumeration was a subtype or a larger enumeration,
and don't know if that matters?)
Finally had to put the type definition back in the private part.
---------------
This is using the verdix compiler v5.41. Anyone care to try it on their
compiler?
--thanks
scott moody @ boeing mountain network
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1988-01-23 18:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1988-01-23 18:13 differed private declarations (Feature/Bug) Scott Moody
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox