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,8522260ffbf09d84 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-11-06 10:00:20 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!elnk-pas-nf1!elnk-nf2-pas!newsfeed.earthlink.net!sjc70.webusenet.com!news.webusenet.com!nf3.bellglobal.com!nf1.bellglobal.com!nf2.bellglobal.com!news20.bellglobal.com.POSTED!not-for-mail From: "Warren W. Gay VE3WWG" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Problem With Self-Referential Access-to-Subprogram Type References: <80teqv099lspc5d4osf2gmu7cld46i0lvb@4ax.com> <20chqvglnrae8njr0011cfg3a8hc82je7m@4ax.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Thu, 06 Nov 2003 12:45:42 -0500 NNTP-Posting-Host: 198.96.223.163 X-Complaints-To: abuse@sympatico.ca X-Trace: news20.bellglobal.com 1068140710 198.96.223.163 (Thu, 06 Nov 2003 12:45:10 EST) NNTP-Posting-Date: Thu, 06 Nov 2003 12:45:10 EST Organization: Bell Sympatico Xref: archiver1.google.com comp.lang.ada:2159 Date: 2003-11-06T12:45:42-05:00 List-Id: Tad Ashlock wrote: > Marius Amado Alves wrote in message news:... > >>On Wed, 2003-11-05 at 17:49, Adam Beneschan wrote: >> >>>... The feeling at the time was that >>>the additional work needed to change the language and the compilers >>>shouldn't be required if no one has run into the problem in practice. >>>I've let them know that someone now has run into it. >> >>Did you verify that the problem was "real"? The example does not seem to >>show enough. Can be just an experimentation of the general construction, >>with no specific application in mind. Some newbies do that. (In which >>case the 2002 decision should probably stand. Private types solve the >>general problem.) > > Well, as the OP I can't really say how "real" the problem is. But I > can describe what it is I'm trying to accomplish. > > What I'm trying to do is implement (in Ada) the ideas in the book > "Practical Statecharts in C/C++" by Miro Samek, CMP Books, 2002, ISBN > 1-57820-110-1 . The > (quite ingenious) idea is that the current state of a hierarchical > state machine can be represented by nothing more than a reference (a > function pointer in C++) to the state handling function. And to > implement the hierarchical aspect of statecharts, each state handling > function returns a reference to its parent state if it doesn't handle > the passed-in event itself. > > Of course there are other ways of getting the required information > back from the state handler, but I am trying to keep the Ada > implementation similar to the original C++ implementation. At least I know this doesn't map to the "C++ way", but would not an array of function pointers with an enumerated type to choose the function not work? Rather than working with "pointers", directly, you choose the pointer using the enumerated type as an array subscript. This also avoids violating the "never compare pointers" rule (not all platforms guarantee that the representation of 2 equivalent addresses will be identical). This may come up when you need to compare if one state is equal to another. Comparing pointers may work on most modern platforms, it is not guaranteed to work (I think segmented architectures is where you have the greatest difficulty with this). -- Warren W. Gay VE3WWG http://home.cogeco.ca/~ve3wwg