From: Simon Wright on
Georg Bauhaus <rm.dash-bauhaus(a)futureapps.de> writes:

> with Ada.Text_IO; use Ada.Text_IO;
>
> procedure Sttc is
>
> type T is range 0 .. 10;
>
> procedure A is
> package P is
> V: T;
pragma Export (C, V, "naughty_v"); --<<<<<<<<<<
> end P;
> begin
> if P.V'Valid then
> P.V := P.V + 1;
> else
> P.V := T'First;
> end if;
> Put_Line (T'Image(P.V));
> end A;
>
> procedure Ovrwrt_Stk is
> X : T;
> begin
> X := T'First;
> end Ovrwrt_Stk;
>
> begin
> A; Ovrwrt_Stk; A; Ovrwrt_Stk; A; Ovrwrt_Stk; A;
> end Sttc;
>
> $ ./sttc
> 0
> 1
> 1
> 1
> $
>
> Phew. Back to normal.

$ gnatmake sttc -f -gnatVa
gcc -c -gnatVa sttc.adb
sttc.adb:10:28: warning: "V" has been made static as a result of Export
sttc.adb:10:28: warning: this usage is non-standard and non-portable
gnatbind -x sttc.ali
gnatlink sttc.ali
$ ./sttc
1
2
3
4

(this is a GNAT-ism, of course, and is present in at least GNAT Pro
3.16a1 for powerpc-wrs-vxworks and GCC 4.5.0 for x86_64-apple-darwin10).
From: Niklas Holsti on
Simon Wright wrote:
> Georg Bauhaus <rm.dash-bauhaus(a)futureapps.de> writes:
>
>> with Ada.Text_IO; use Ada.Text_IO;
>>
>> procedure Sttc is
>>
>> type T is range 0 .. 10;
>>
>> procedure A is
>> package P is
>> V: T;
> pragma Export (C, V, "naughty_v"); --<<<<<<<<<<
>> end P;
>> begin
>> if P.V'Valid then
>> P.V := P.V + 1;
>> else
>> P.V := T'First;
>> end if;
>> Put_Line (T'Image(P.V));
>> end A;
>>
>> procedure Ovrwrt_Stk is
>> X : T;
>> begin
>> X := T'First;
>> end Ovrwrt_Stk;
>>
>> begin
>> A; Ovrwrt_Stk; A; Ovrwrt_Stk; A; Ovrwrt_Stk; A;
>> end Sttc;
>>
>> $ ./sttc
>> 0
>> 1
>> 1
>> 1
>> $
>>
>> Phew. Back to normal.
>
> $ gnatmake sttc -f -gnatVa
> gcc -c -gnatVa sttc.adb
> sttc.adb:10:28: warning: "V" has been made static as a result of Export
> sttc.adb:10:28: warning: this usage is non-standard and non-portable
> gnatbind -x sttc.ali
> gnatlink sttc.ali
> $ ./sttc
> 1
> 2
> 3
> 4
>
> (this is a GNAT-ism, of course, and is present in at least GNAT Pro
> 3.16a1 for powerpc-wrs-vxworks and GCC 4.5.0 for x86_64-apple-darwin10).

It is also present in GNAT 4.3 in debian lenny.

You can even initialize V in its declaration, for example as V : T : =
T'First, and GNAT will make this initialization happen once. No need for
the unreliable trickery with 'Valid.

Interesting curio to know, but as for using it... nah.

--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .
From: Randy Brukardt on
"AdaMagica" <christoph.grein(a)eurocopter.com> wrote in message
news:4db36585-569d-4f24-ab95-0c7177e5d09b(a)d8g2000yqf.googlegroups.com...
On 10 Jun., 08:13, "Randy Brukardt" <ra...(a)rrsoftware.com> wrote:
>> When this is done, even the use of objects of 'Class can be managed with
>> Ada.Containers, and any needed dynamic allocation can be completely
>> hidden
>> from the program. (And it rarely is needed in the first place.)
>
>Randy, which AI is the favoured solution (there are several
>proposals)? The current Amendment 2 RM is still Draft 8 which does not
>include this accessor magic.

Right. AI05-0139-2 contains the syntax, AI05-0142-4 contains a related
feature, and AI05-0212-1 contains the changes needed to the predefined
containers for the first two.

I'd wait to read those until next week; Tucker is supposed to be providing
major updates to AI05-0139-2 and AI05-0142-4 by tomorrow afternoon and I'll
be posting them over the weekend before leaving for Vallencia. (AI05-0212-1
is mostly empty still, waiting for the other two to get much closer to
completion. We had problems deciding on names of things in the past (even
though no one use those names, we still have to have them), but otherwise
the basic structure is already known).

Also in the next few days, the next AARM draft will be posted.

Randy.


From: Randy Brukardt on
"Vadim Godunko" <vgodunko(a)gmail.com> wrote in message
news:35dd1a8f-1af8-4979-9663-29f7f4cb302e(a)g19g2000yqc.googlegroups.com...
On Jun 10, 10:54 am, Yannick Duch�ne (Hibou57)
<yannick_duch...(a)yahoo.fr> wrote:
>> Le Thu, 10 Jun 2010 08:34:07 +0200, Vadim Godunko <vgodu...(a)gmail.com> a
>> �crit:> I want to known more about how to use OOP in Ada without access
>> types!
>>
>> Wadim, if saying OOP, you meant dynamic dispatching, then you are indeed
>> not required to use access type for that.
>No, I more asked for real example where Ada's OOP is be used without
>access types in OOP way. The only known example is Tuker's work on
>some part of ASIS 05, but from my point of view this work is set of
>tricks and assumptions successful for concrete example but not for
>general use.

Claw only uses a handful of access types in its interfaces (internally is a
different story, but irrelevant to this discussion). Most Claw example
programs use no access types at all.

> By "access types" I mean access to classwide types.

If you need to do this, using an indefinite container to hold the objects is
preferable to using explicit access types. Again, access types probably are
used to implement the container, but they aren't visible anywhere. This
eliminates the horrors of explicit storage management and most (or all,
depending on the implementation) of the unsafeness of access types without
any distributed overhead. (Unlike garbage collection, which has to be done
on all objects to work, so even objects that don't need management have to
pay for it.)

Randy.



From: Randy Brukardt on
"Georg Bauhaus" <rm.dash-bauhaus(a)futureapps.de> wrote in message
news:4c10baa2$0$6974$9b4e6d93(a)newsspool4.arcor-online.net...
> On 10.06.10 10:57, Vadim Godunko wrote:
>> On Jun 10, 11:20 am, AdaMagica <christoph.gr...(a)eurocopter.com> wrote:
>>> On 10 Jun., 08:34, Vadim Godunko <vgodu...(a)gmail.com> wrote:
>>>
>>>> I want to known more about how to use OOP in Ada without access types!
>>>
>>> type Element is tagged ...
>>> subtype Any_Element is Element'Class;
>>>
>>> procedure Show (E: Element);
>>>
>> Thank you for example, this is example of dispatching but not use of
>> Ada in heavy OOP style of programming. :-)
>
> Will it, in theory, be possible to write a Qt-like library
> in Ada such that client programs declare variables like
>
> W : Some_Window'Class := Some_Lib_Pack.Make (Typ => Some_Id);
>
> That is, programs do not use access Some_Window'Class?

We could have done this in Claw, but we found little need for "generic
windows". At some point, you have to declare the specific window object that
you need, and at that point you might as well just declare an object of that
type.

Claw allows window objects to be assigned, so you could definitely do
something like:

declare
My_Window : Claw.Basic_Window.Window;
begin
Global_Window := Root_Window_Type'Class(My_Window);
end;

Unfortunately, Ada doesn't allow the changing of the tags of declared
classwide objects. (This is a language bug in my view, but hardly anyone
elses.) So you have to use an Ada 2012 holder container:

declare
My_Window : Claw.Basic_Window.Window;
begin
Global_Window.Replace_Element (Root_Window_Type'Class(My_Window));
end;

where Global_Window is defined as:

package Global_Holder is new Ada.Containers.Indefinite_Holder
(Claw.Root_Window_Type'Class);

Global_Window : Global_Holder;


Randy.