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=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.66.217.170 with SMTP id oz10mr14593649pac.9.1404743013501; Mon, 07 Jul 2014 07:23:33 -0700 (PDT) X-Received: by 10.182.29.38 with SMTP id g6mr42596obh.12.1404743013115; Mon, 07 Jul 2014 07:23:33 -0700 (PDT) Path: border2.nntp.dca.giganews.com!nntp.giganews.com!goblin3!goblin1!goblin2!goblin.stu.neva.ru!feeder.erje.net!us.feeder.erje.net!news.glorb.com!uq10no2364003igb.0!news-out.google.com!bp9ni2747igb.0!nntp.google.com!hn18no4533367igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 7 Jul 2014 07:23:32 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=73.179.102.101; posting-account=wEPvUgoAAABrLeiz_LRhQ3jeEhyfWVMH NNTP-Posting-Host: 73.179.102.101 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <35cd9c91-4b2c-4baa-9ef6-3c69fd7086ce@googlegroups.com> Subject: Re: Protected Type compiler complaint From: NiGHTS Injection-Date: Mon, 07 Jul 2014 14:23:33 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: number.nntp.dca.giganews.com comp.lang.ada:187424 Date: 2014-07-07T07:23:32-07:00 List-Id: On Monday, July 7, 2014 3:55:24 AM UTC-4, Simon Wright wrote: > > When I compile it complains that "protected declaration cannot be used >=20 > > as compilation unit" on line 1 of test.ads. So I remove those files >=20 > > from the project source files options menu. Then when I compile again >=20 > > it complains about "test.ads not found" on line 3 of main.adb. >=20 >=20 >=20 > A protected declaration cannot be used as a compilation unit; it has to >=20 > be declared within one. >=20 >=20 >=20 > > Here is a summarized view of what my test.ads looks like: >=20 > > >=20 > > protected type Test is procedure DoSomething; end Test; >=20 >=20 >=20 > package Test is >=20 > protected type P is >=20 > procedure Do_Something; >=20 > end P; >=20 > end Test; >=20 >=20 >=20 > > And here is a summarized view of what my main.adb looks like: >=20 > > >=20 > > with Test; use Test; >=20 > > >=20 > > procedure main is begin Test.DoSomething; end; >=20 >=20 >=20 > You made Test a protected *type* (and I've suggested Test.P), so you >=20 > need to declare a protected *object* of that type. >=20 >=20 >=20 > with Test; >=20 > procedure Main is >=20 > O : Test.P; >=20 > begin >=20 > O.Do_Something; >=20 > end Main; Thank you for your help. This makes sense.=20 A question about the variables in the Test.P type you introduced. I would l= ike to make available to other spawned tasks these protected variables, so = essentially Test.P needs to be a global of some kind with static data in th= e currently running process. I heard much about not creating global variabl= es for good Ada coding practice, so how is this protected package variables= expected to be usable by these spawned tasks?=20 NOTE: The task code may not be directly associated to the main package as I= expect to create task utility packages shared by multiple applications. Thank you again for your help.