* Programming by interface in Ada @ 2008-08-13 11:14 Sébastien Morand 2008-08-13 15:31 ` Adam Beneschan 0 siblings, 1 reply; 5+ messages in thread From: Sébastien Morand @ 2008-08-13 11:14 UTC (permalink / raw) -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I'm trying to do the following thing: - --- pkginterface.ads ------------------------------- with ObjInterface; use ObjInterface; package PkgInterface is -- Mon interface class type MonInterface is interface; type MonInterfacePtr is access all MonInterface; procedure SetObjet(r: in out MonInterface; c: in MonCount; o: in MonObjetPtr) is abstract; end PkgInterface; - --- objinterface.ads ------------------------------- package ObjInterface is -- Mon interface class type MonObjet is interface; type MonObjetPtr is access all MonObjet; end ObjInterface; - --- pkgimpl.ads ------------------------------- with PkgInterface; use PkgInterface; with ObjInterface; use ObjInterface; package PkgImpl is type MonImpl is new MonInterface with private; type MonImplPtr is access all MonImpl; overriding procedure SetObjet(r: in out MonImpl; c: in MonCount; o: in MonObjetPtr); private type MonImpl is new MonInterface with record a: MonObjetPtr; end record; end PkgImpl; - --- pkgimpl.adb ------------------------------- package body PkgImpl is procedure SetObjet(r: in out MonImpl; c: in MonCount; o: in MonObjetPtr) is begin r.a := o; end SetObjet; end PkgImpl; - ---------------------------------- When I'm trying to compile pkgimpl.adb I get the following error: pkgimpl:5:04: (Ada 2005) : abstract interface primitives must be defined in package specs. The interface primitive it's yelling about should be SetObjet which is correctly defined in the spec. So waht's the matter? It looks like the MonObjetPtr (access all ObjInterface) is the real problem. How can I achieve this? Thanks by advance, Sebastien -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (Cygwin) iD8DBQFIosID+zV9xm4PlDQRAnLLAJ9pHuAdVnQNrITgRZ1/RmCdGGLviwCbBggP Fy0SSIMKb5/AM03KDKaq+WA= =35KI -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Programming by interface in Ada 2008-08-13 11:14 Programming by interface in Ada Sébastien Morand @ 2008-08-13 15:31 ` Adam Beneschan 2008-08-13 16:08 ` Marcus Lauster ` (2 more replies) 0 siblings, 3 replies; 5+ messages in thread From: Adam Beneschan @ 2008-08-13 15:31 UTC (permalink / raw) On Aug 13, 4:14 am, Sébastien Morand <seb.mor...@gmail.com> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi, > > I'm trying to do the following thing: > > - --- pkginterface.ads ------------------------------- > with ObjInterface; use ObjInterface; > > package PkgInterface is > > -- Mon interface class > type MonInterface is interface; > type MonInterfacePtr is access all MonInterface; > > procedure SetObjet(r: in out MonInterface; c: in MonCount; o: in > MonObjetPtr) is abstract; > > end PkgInterface; > > - --- objinterface.ads ------------------------------- > package ObjInterface is > > -- Mon interface class > type MonObjet is interface; > type MonObjetPtr is access all MonObjet; > > end ObjInterface; > > - --- pkgimpl.ads ------------------------------- > with PkgInterface; use PkgInterface; > with ObjInterface; use ObjInterface; > > package PkgImpl is > > type MonImpl is new MonInterface with private; > type MonImplPtr is access all MonImpl; > > overriding > procedure SetObjet(r: in out MonImpl; c: in MonCount; o: in MonObjetPtr); > > private > > type MonImpl is new MonInterface with record > a: MonObjetPtr; > end record; > > end PkgImpl; > > - --- pkgimpl.adb ------------------------------- > package body PkgImpl is > > procedure SetObjet(r: in out MonImpl; c: in MonCount; o: in > MonObjetPtr) is > begin > r.a := o; > end SetObjet; > > end PkgImpl; > - ---------------------------------- > > When I'm trying to compile pkgimpl.adb I get the following error: > pkgimpl:5:04: (Ada 2005) : abstract interface primitives must be defined > in package specs. > > The interface primitive it's yelling about should be SetObjet which is > correctly defined in the spec. So waht's the matter? It looks like the > MonObjetPtr (access all ObjInterface) is the real problem. > > How can I achieve this? > > Thanks by advance, Well, I've found that if you change type MonObjetPtr is access all MonObjet; to type MonObjetPtr is access all MonObjet'Class; the error goes away. There is no Ada reason why this should be so. I think your program is legal and GNAT has a bug. Maybe it's incorrectly applying a rule for anonymous-access parameters to your MonObjetPtr parameter. But I also see no reason to use "access all MonObjet;" anyway, without the 'Class. Since you can't have objects of type MonObjet, declaring an access to this object (rather than to MonObjet'Class) doesn't seem worthwhile. I think you can make it work by type conversions---you can convert an "access all MonObjet'Class" to an "access all MonObjet" and vice versa, but you can't use an "access all MonObjet" without all those type conversions, so there doesn't seem to be much point in declaring it that way. So that's what I'd do. And the same thing with MonInterfacePtr. By the way, may I make a request of anyone who posts this sort of question? If it involves a GNAT error, please do something extra to indicate what line the error is occurring on. The error message in the post indicated that the error was on line 5, but that's not helpful at all---I can't tell from the post which line is line 5. (For one thing, one of the Ada lines got line-wrapped by my newsreader. For another thing, I can't tell which of the comment lines are actually part of the source file.) Of course, I can figure out what's going on by cutting-and-pasting the source and trying it myself, but that's extra work, plus it's not always feasible if there are missing declarations (e.g. you didn't include the declaration of MonCount in the above source, although that was easy to fix). Maybe this is too much to ask, but I do ask that posters be aware that our newsreaders will not always display the source exactly as your compiler sees it. Thanks. -- Adam ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Programming by interface in Ada 2008-08-13 15:31 ` Adam Beneschan @ 2008-08-13 16:08 ` Marcus Lauster 2008-08-13 17:00 ` Robert A Duff 2008-08-13 17:42 ` Ludovic Brenta 2 siblings, 0 replies; 5+ messages in thread From: Marcus Lauster @ 2008-08-13 16:08 UTC (permalink / raw) Adam Beneschan schrieb: > On Aug 13, 4:14 am, S�bastien Morand <seb.mor...@gmail.com> wrote: [...] >> The interface primitive it's yelling about should be SetObjet which is >> correctly defined in the spec. So waht's the matter? It looks like the >> MonObjetPtr (access all ObjInterface) is the real problem. >> >> How can I achieve this? >> >> Thanks by advance, > > Well, I've found that if you change > > type MonObjetPtr is access all MonObjet; > > to > > type MonObjetPtr is access all MonObjet'Class; > > the error goes away. There is no Ada reason why this should be so. I > think your program is legal and GNAT has a bug. Maybe it's > incorrectly applying a rule for anonymous-access parameters to your > MonObjetPtr parameter. > Maybe there is a reason. For me it seems to be ok, because an interface is a abstract type and therefore you aren't allowed to create an object. And as a consequence of this it seems that you also aren't allowed to create a direct reference to it. But you can have a reference to all objects wich are subsumed by this type. I'm new to Ada if my toughts are going into the wrong direction correct me please. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Programming by interface in Ada 2008-08-13 15:31 ` Adam Beneschan 2008-08-13 16:08 ` Marcus Lauster @ 2008-08-13 17:00 ` Robert A Duff 2008-08-13 17:42 ` Ludovic Brenta 2 siblings, 0 replies; 5+ messages in thread From: Robert A Duff @ 2008-08-13 17:00 UTC (permalink / raw) Adam Beneschan <adam@irvine.com> writes: > By the way, may I make a request of anyone who posts this sort of > question? If it involves a GNAT error, please do something extra to > indicate what line the error is occurring on. Or you could include a listing generated by the compiler, with interspersed error messages. - Bob ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Programming by interface in Ada 2008-08-13 15:31 ` Adam Beneschan 2008-08-13 16:08 ` Marcus Lauster 2008-08-13 17:00 ` Robert A Duff @ 2008-08-13 17:42 ` Ludovic Brenta 2 siblings, 0 replies; 5+ messages in thread From: Ludovic Brenta @ 2008-08-13 17:42 UTC (permalink / raw) Adam Beneschan wrote: > By the way, may I make a request of anyone who posts this sort of > question? If it involves a GNAT error, please do something extra to > indicate what line the error is occurring on. [...] May I ask that, in addition, you also specify the exact version of the compiler and operating system, in particular if the operating system is Debian or based on Debian, because of the patches included in gnat on this platform. Thanks. -- Ludovic Brenta. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-08-13 17:42 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2008-08-13 11:14 Programming by interface in Ada Sébastien Morand 2008-08-13 15:31 ` Adam Beneschan 2008-08-13 16:08 ` Marcus Lauster 2008-08-13 17:00 ` Robert A Duff 2008-08-13 17:42 ` Ludovic Brenta
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox