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-Thread: 103376,591cbead201d7f34 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!newscon02.news.prodigy.net!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Prohibiting dynamic allocation for the given type Date: Wed, 19 Mar 2008 20:43:56 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <83335709-e099-416b-9967-5ab6aa0aea11@i12g2000prf.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1205973836 3026 192.74.137.71 (20 Mar 2008 00:43:56 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Thu, 20 Mar 2008 00:43:56 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:7kGruqVPptgn2Rco54h8571v/Cs= Xref: g2news1.google.com comp.lang.ada:20498 Date: 2008-03-19T20:43:56-04:00 List-Id: Maciej Sobczak writes: > Is it possible to "prohibit" dynamic allocation for the given type? I don't know of any simple way to do that. > Let's suppose that I have a type which instances make sense only on > the stack. Could you please give some examples of such a type? Somebody mentioned a lock, which I find only half convincing. Any others? >... I want to prohibit users from dynamically allocating > instances of this type so that they don't get into troubles. > Preferably at compile-time. > > My understanding is that it cannot be done (allocation is not > considered to be a type's operation and there is no way to "hide" it > from users - as is possible in C++), but I would like to have it > confirmed. Well, you can prohibit clients from creating any objects at all (heap or stack) by using (<>) discrims, and not exporting any constructor functions. But that's not what you asked for. - Bob