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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,72c34c66b38e0e05 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-12-30 07:15:25 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn13feed!wn11feed!wn12feed!worldnet.att.net!208.49.253.98!newsfeed.news2me.com!newsfeed2.easynews.com!newsfeed1.easynews.com!easynews.com!easynews!uunet!dfw.uu.net!ash.uu.net!world!news From: Robert A Duff Subject: Re: Proposal: Constructors, Assignment [LONG] User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Mon, 30 Dec 2002 15:14:34 GMT Content-Type: text/plain; charset=us-ascii References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Organization: The World Public Access UNIX, Brookline, MA Xref: archiver1.google.com comp.lang.ada:32388 Date: 2002-12-30T15:14:34+00:00 List-Id: "Dmitry A. Kazakov" writes: [various stuff about constructors] You should look at AI-287, which says that aggregates are allowed for limited types. Also, AI-318 which allows constructor functions for limited types. I don't see any reason to add a new feature. It seems to me that the problem is that you can't write a constructor function for a limited type (i.e., a function that creates a new object local to itself, and returns it), and you can't initialize limited objects. So the solution is simply to remove these restrictions. To build on your example: type Internet_Session is abstract new Ada.Finalization.Limited_Controlled with record Count: Integer; Previous : Internet_Session_Ptr; -- In the global list Next : Internet_Session_Ptr; -- of sessions end record; type Session_Ptr is access Internet_Session; function Make_Session(Count: Integer) return Internet_Session is Result: Internet_Session := (Count => Count, Previous | Next => <>); -- use default "null" begin Result.Previous := ...; ... return Result; end Make_Session; Then clients could initialize stack and heap objects by calling the constructor function: This_Session: Internet_Session := Make_Session(Count => 123); That_Session: Session_Ptr := new Internet_Session'(Make_Session(123)); The above aggregate is currently illegal, and the "return Result" won't work because it violates accessibility rules. And the two initial values are currently illegal. The two AI's would allow the above. I'm glossing over some details that are probably documented either in the AI's, or in the minutes of some ARG meeting. The main point is that limited types are *too* limited. Their purpose is to prevent *copying* (assignment statements). But initialization is *not* like an assignment, it need not involve a copy, and it should be allowed for limited types. > The problem is not only the limited types. The problem is more general. It > is user-construction/destruction for ALL user-defined types. I don't understand that. Functions work fine as constructors for non-limited types. The problem is for limited types. As for destructors, well Ada.Finalization works OK, although it has some flaws. Those flaws seem unrelated to the constructor-for-limited-type issue. >...It is > user-assignment for ALL non-limited user-defined types. That seems like a totally unrelated issue. > 1. Your proposal is based on a bitwise copy[-constructor]... The whole point of limited types is that they *cannot* be copied. Access discriminants don't work if copies are made. Locks in protected objects don't work. Various data structures involving pointers don't work, as your example showed. Etc. It is important that the Result object of Make_Session above be built in place, in its final destination. It cannot be built on the local stack frame and then moved elsewhere. This requires that the compiler pass in a Storage_Pool object telling it where to allocate. A special Storage_Pool could mean "on the stack", but in the That_Session initialization above, the object must be allocated in the storage pool belonging to Session_Ptr, which could be user defined. - Bob