From: Martin Krischik on
Am 27.10.2005, 02:01 Uhr, schrieb Szymon Guz <alpha(a)skynet.org.pl_WITHOUT>:

> Hi,
> I've got some maybe stupid questions but I don't understand some things:
>
> 1. Is there a pointer like (void *) from C that points to anything ?

Read:

http://en.wikibooks.org/wiki/Ada_Programming/Types/access#Where_is_void.2A.3F

And all the text above that sub-chapter.

> 2. Is there a universal (like above) pointer for procedure|function that
> can point to any kind of procedure|funcion ?

How is that supposed to work? Any function - how then are you going to
pass any parameters? You don't even have that in C.

Martin

From: Martin Dowie on
Robert A Duff wrote:
> Maybe the kinds of programs I write are different. Question for those
> who rarely use access types: what sort of application areas are you
> talking about? Mine are usually software development tools -- such as
> compilers.

Embedded defence apps and I can't remember the last time I needed an
access type!

There's no need in this sort of app, as you know at compile time what
the maximum number of anything your system is required to deal with, so
you can always use a lookup table of some sort (even if it has an
'In_Use : Boolean' field/discriminant.

Cheers

-- Martin
From: Jeffrey R. Carter on
Robert A Duff wrote:
>
> Never? Well, these kinds of low-level hacks are _rarely_ a good idea.
> But you might need them when interfacing to some other language
> that uses such trickery.

True, but then you're not using Ada, you're using Ada and X, which I addressed
later. For just Ada, you never need the kind of pointers the OP was asking about.

> Maybe the kinds of programs I write are different. Question for those
> who rarely use access types: what sort of application areas are you
> talking about? Mine are usually software development tools -- such as
> compilers.

Maybe. I use unbounded data structures frequently, but I don't write a new one
every time. Instead, I reuse existing generic data structures, so the code I
write doesn't contain those access types. When you talk about all the access
types in your compiler code, are you talking about frequent creation of new
access types, reuse of existing but exposed access types, or reuse of packages
that hide the use of access types? That will help decide if compilers are different.

For learning Ada, one should write some dynamic data structures, but to use Ada,
you should reuse existing dynamic data structures. I don't count access types
hidden in reused packages as using access types.

Recently, I've written a generic package for genetic algorithms, and a TSP
program that uses it, and a package to implement the Nicias encryption
algorithm, and a program that uses it. Nary an access type in sight.

> If I designed a language, I would go even further in that direction.
> I would allow mutually recursive types without intervening pointers.
> The only need for pointers in my language would be where
> reference semantics is desired -- e.g. when you want two pointers
> to the same object, such that updates to that object can be seen
> through both.

We're still waiting to see an informal specification for Duff, or whatever it's
called :)

> I don't really agree. A beginner to Ada who knows how to program
> (in some other language, such as C) might well want to make a
> linked list, for example, and that requires pointers of some
> sort -- usually access types.

Again, for learning Ada, certainly. For using Ada, no. Part of learning Ada is
learning to reuse. Even after the beginner has crafted a generic, unbounded list
to learn about generics, access types, memory management, and information
hiding, it's still a good idea for him to use the unbounded list component from
<your favorite library here> (or Ada.Containers in 0X) to learn to reuse others'
packages, and to gain the benefit of SW that has been much more thoroughly
tested than his own effort.

My comments that pointers are rarely needed in Ada are usually addressed to
beginners coming from C who think they must use pointers for everything, from
passing a parameter that can be modified to creating an array with bounds known
only at run time. I hope that my saying this will cause them to stop, every time
they think they need a pointer, and see if perhaps Ada can do it without one. In
that way, perhaps they will gain a better understanding and appreciation of Ada.

--
Jeff Carter
"My mind is aglow with whirling, transient nodes of
thought, careening through a cosmic vapor of invention."
Blazing Saddles
85
From: Marc A. Criley on
Martin Dowie wrote:
> Robert A Duff wrote:
>
>> Maybe the kinds of programs I write are different. Question for those
>> who rarely use access types: what sort of application areas are you
>> talking about? Mine are usually software development tools -- such as
>> compilers.
>
>
> Embedded defence apps and I can't remember the last time I needed an
> access type!
>
> There's no need in this sort of app, as you know at compile time what
> the maximum number of anything your system is required to deal with, so
> you can always use a lookup table of some sort (even if it has an
> 'In_Use : Boolean' field/discriminant.

Now that is exactly the domain where I would expect to not see access
types, for the reasons you cite (as well as related reasons having to do
with predictability and the consequences of errors.)

-- Marc A. Criley
-- McKae Technologies
-- www.mckae.com
-- DTraq - XPath in Ada - XML EZ Out
From: Jeffrey R. Carter on
Marc A. Criley wrote:

> I agree. The Ada projects I've worked on, from flight simulators, to command
> and control systems, to data analysis tools, to software development tools,
> have all made use of pointers, some more than others. There's so much
> dynamic activity going on, often with no way to know in advance just what to
> expect in terms of configuration, ordering, etc.

For $2500/day or part thereof, with a minimum charge of 5 days, I'm sure I could
tell you how to eliminate many of those pointers :)

> In some thread that once touched on this subject, I vaguely recall someone
> saying one shouldn't use pointers, instead an appropriate container should be
> used. Okay, so the pointers are being wrapped in a container. That's not
> what I'd call "not needing pointers", they're just not out in plain sight.

Perhaps it would be more accurate to say that one will rarely need to declare or
manipulate pointers directly, but saying one will rarely need pointers is more
succinct, and more in line with what things look like to someone who is reusing
a dynamic data structure package.

Of course, "rarely" is not "never".

--
Jeff Carter
"My mind is aglow with whirling, transient nodes of
thought, careening through a cosmic vapor of invention."
Blazing Saddles
85