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: a07f3367d7,5d6e2ad0b6f4137a X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!news.flashnewsgroups.com-b7.4zTQh5tI3A!not-for-mail Newsgroups: comp.lang.ada Subject: Re: This MIDI stuff, would someone be interested in reviewing my code? References: From: Stephen Leake Date: Wed, 10 Mar 2010 06:12:11 -0500 Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (windows-nt) Cancel-Lock: sha1:FgrGwWYVq534ntt8vxHr02+sNY8= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@flashnewsgroups.com Organization: FlashNewsgroups.com X-Trace: 844c44b977eb9e197caa721461 Xref: g2news1.google.com comp.lang.ada:9508 Date: 2010-03-10T06:12:11-05:00 List-Id: John McCabe writes: > On Tue, 09 Mar 2010 12:26:21 +0000, John McCabe > wrote: > >>On Tue, 09 Mar 2010 12:10:16 +0000, Brian Drummond >> wrote: > >>>>>For this small >>>>>example, I would do the same with Midiincaps and Midioutcaps; > >>>>The point of allocating/freeing them was to get round the fact that, >>>>when they were declared in the declarative part of the main function, >>>>I seemed to have to use 'Unchecked_Access when passing them to >>>>midiInGetDevCaps/midiOutGetDevCaps. > >>>Look into the "aliased" keyword. Unlike C, the compiler will assume a local >>>variable is never aliased (and can be optimised) - unless you declare it >>>aliased, to say there may be a pointer to it. Declare them aliased and you >>>shouldn't need Unchecked_Access. > >>I had them declared as aliased. With just 'access on it the compiler >>said "blah blah blah can't do it because it's not global" (or >>something like that). I'll check again, but that was the gist of it. > > mididevs.adb:56:49: non-local pointer cannot point to local object > > Note - this is an updated version so the lines aren't the same number! > > That's with something like: > > procedure MidiDevs is > Midi_In_Caps : aliased Win32.Mmsystem.MIDIINCAPS; This object is declared in a procedure, and is therefore allocated on the stack. > begin > > res := Win32.Mmsystem.midiInGetDevCaps(Device_ID, > Midi_In_Caps'Access, This function takes a parameter of a global access type. So in theory, the function could store a copy of the pointer, and then use it after MidiDevs has returned, and the actual object disappeared. That's why this is illegal. However, if MidiDevs is really your main procedure, then Midi_In_Caps will never disappear, and 'Unchecked_Access is safe. -- -- Stephe