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=0.6 required=5.0 tests=BAYES_05,INVALID_DATE, MSGID_SHORT autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!water!watmath!clyde!rutgers!mit-eddie!uw-beaver!ssc-vax!shuksan!scott From: scott@shuksan.UUCP (Scott Moody) Newsgroups: comp.lang.ada Subject: differed private declarations (Feature/Bug) Keywords: limited private Message-ID: <531@shuksan.UUCP> Date: 23 Jan 88 18:13:07 GMT Organization: The Boeing Co., BAC MMST, Seattle, WA List-Id: 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