comp.lang.ada
 help / color / mirror / Atom feed
From: scott@shuksan.UUCP (Scott Moody)
Subject: differed private declarations  (Feature/Bug)
Date: 23 Jan 88 18:13:07 GMT	[thread overview]
Message-ID: <531@shuksan.UUCP> (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

                 reply	other threads:[~1988-01-23 18:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
replies disabled

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