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,5d38b71c771be34e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-07-12 19:32:06 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news.tele.dk!small.news.tele.dk!207.115.63.138!newscon04.news.prodigy.com!newsmst01.news.prodigy.com!prodigy.com!postmaster.news.prodigy.com!newssvr13.news.prodigy.com.POSTED!3bae8248!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Unchecked Deallocation? References: X-Newsreader: Tom's custom newsreader Message-ID: <0iMX8.163$9H5.5573815@newssvr13.news.prodigy.com> NNTP-Posting-Host: 67.112.202.136 X-Complaints-To: abuse@prodigy.net X-Trace: newssvr13.news.prodigy.com 1026527484 ST000 67.112.202.136 (Fri, 12 Jul 2002 22:31:24 EDT) NNTP-Posting-Date: Fri, 12 Jul 2002 22:31:24 EDT Organization: Prodigy Internet http://www.prodigy.com X-UserInfo1: Q[R_@SVGXZUWSVPXN[O@_WH@YR_B@EXLLBWLOOAFEQR@ETUCCNSKQFCY@TXDX_WHSVB]ZEJLSNY\^J[CUVSA_QLFC^RQHUPH[P[NRWCCMLSNPOD_ESALHUK@TDFUZHBLJ\XGKL^NXA\EVHSP[D_C^B_^JCX^W]CHBAX]POG@SSAZQ\LE[DCNMUPG_VSC@VJM Date: Sat, 13 Jul 2002 02:31:24 GMT Xref: archiver1.google.com comp.lang.ada:27039 Date: 2002-07-13T02:31:24+00:00 List-Id: > with unchecked_deallocation; > generic > type Item is private; >package genstack is -- A basic generic stack. Singlely linked list. -- You needn't 'with' unchecked_deallocation here since you never use it in the package spec. It's only used in the body, so you could move this 'with' there. BTW, "Unchecked_Deallocation" is obsolescent Ada 83 naming. It's not much more typing, and might save someone a headache in the future, to use the modern form "Ada.Unchecked_Deallocation". > procedure Free is new Unchecked_Deallocation(Cell, Stack); > function Clear_Stack(S : in Stack) return Boolean is -- Return True or > begin > Free(Stack); | >>> Invalid use of subtype mark in expression or call >>> actual for 'X' must be a variable What particular stack might you possibly mean to free? If your program used pointers to integers, would you say "Free(Integer)" when you wanted to get rid of one? You need, as the error message said, to call Free with the name of a particular stack to free, presumably S in this case, not the name of a type. Since the parameter to Free is "in out", S will have to be "in out", which means Clear_Stack can't be a function (as previously pointed out). A function that always returns the same value is not much of a function, anyway. And as pointed out, you probably don't really just want to deallocate the single cell, but rather a whole list of them. Calling a pointer to a cell a stack sets you up for this confusion. You have three different kinds of entities: a data-containing cell, a pointer to such a cell, and a list of related cells. Better to use three different names for three different things. > Cell is defined in the private type and is only accessible via the The private part of a package spec *is* visible to the body of that package, just not visible to other packages. If it was not visible to *any* package body it would be of mighty limited utility.