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.3 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,59e1f81123faf689 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-08-25 16:31:03 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fr.clara.net!heighliner.fr.clara.net!freenix!enst.fr!not-for-mail From: "Steven Deller" Newsgroups: comp.lang.ada Subject: RE: what means the " ' " in use with a record type? Date: Sun, 25 Aug 2002 18:29:04 -0500 Organization: Smooth Sailing LLC Sender: comp.lang.ada-admin@ada.eu.org Message-ID: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: avanie.enst.fr 1030318262 34864 137.194.161.2 (25 Aug 2002 23:31:02 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Sun, 25 Aug 2002 23:31:02 +0000 (UTC) Return-Path: X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Importance: Normal In-Reply-To: Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.12 Precedence: bulk X-Reply-To: List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:28398 Date: 2002-08-25T18:29:04-05:00 > If x is an access to type node, why is the qualified expression > > needed, while it's not needed in: > > type fruits is (apple, orange, banana); > > type colors is (red, orange, yellow); > > color : colors; > > fruit : fruits; > > begin > > color := orange; > > fruit := orange; T(x) is a type conversion (cast :-)) of x to type T. The actual type of "x" need only be compatible with T, not "of" type T. T'(x) on the other hand is an "x" of type T. Qualification is needed in many cases having nothing to do with allocators. See 4.7 for examples of some. > As I recall, the original reason for the apostrophe is > because, in the absence of this feature, the general construct > new T(expr) > could be ambiguous (or at least confusing to the human > reader) in some contexts -- i.e., is expr the value of a > discriminant, or is it an initialization for the allocated > object? No. It means something different with and without the apostrophe. If it were legal Ada to write: type A is access Node ; P : A ; ... P := new Node(x) ; ... or simply P := new (x) ; then the type of x could be anything compatible with Node. In particular, if Node were derived from N without any extensions, then x's value could be of either Node or N. That may seem trivial, until you consider type attributes, where N might be allocated from shared memory (using a user-specified allocator), while Node is in default (non-shared) memory. You could argue that Ada just ought to "do the simple/right thing", but that is a slippery slope to C-style disasters. Better that the language force the writer to be specific about the type intended. Plus there is no "right" thing when you have tagged types with extensions: procedure Test_Ada is type A is tagged record X : integer ; end record ; type B is tagged record Y : integer ; end record ; type C is tagged record Z : integer ; end record ; type P is access A'class ; O : P ; begin O := new B'(X => 3, others => 4 ) ; -- "B" or "C" is legal here ... ; Ada makes you say what you mean Regards, Steve Deller (the "other" SteveD :-)) deller@smsail.com