|
Prev: Survey on the Effects of Organizational Culture on Software Productivity
Next: Eclipse Ada Support - FYI
From: Jeffrey R. Carter on 27 Oct 2005 01:56 Szymon Guz wrote: > 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 ? > > 2. Is there a universal (like above) pointer for procedure|function that > can point to any kind of procedure|funcion ? The short answer, as you've already heard, is No. The long answer is that you'll never need these to use Ada. In fact, you'll rarely need pointers at all. If you think you do, especially for beginning Ada, then you're probably misunderstanding something. About the only time you'd need anything like these is when interfacing to C. Judging from your questions, I suspect your understanding of Ada is not yet at a level where you should be doing that. -- Jeff Carter "From this day on, the official language of San Marcos will be Swedish." Bananas 28
From: Szymon Guz on 27 Oct 2005 06:19 Jeffrey R. Carter napisa³(a): > Szymon Guz wrote: > >> 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 ? >> >> 2. Is there a universal (like above) pointer for procedure|function >> that can point to any kind of procedure|funcion ? > > > The short answer, as you've already heard, is No. > > The long answer is that you'll never need these to use Ada. In fact, > you'll rarely need pointers at all. If you think you do, especially for > beginning Ada, then you're probably misunderstanding something. > > About the only time you'd need anything like these is when interfacing > to C. Judging from your questions, I suspect your understanding of Ada > is not yet at a level where you should be doing that. > Well, that's how I thought but I wanted to ask. The problem that I want to solve is how to create a property in type like that ones in Delphi|Builder, so I have defined the property name, value, read and write functions. I thought that it could be done by defining a generic structure like this: Name Value Get_Function Set_Function when Value is a pointer to value, Get and Set are pointers to function for setting and getting the value. That's why I thought about universal variable pointer. ......................... Well, now I sought that it ca easily be done without any pointer, sorry regards szymon guz
From: Robert A Duff on 27 Oct 2005 10:11 "Jeffrey R. Carter" <spam(a)spam.com> writes: > Szymon Guz wrote: > > > 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 ? > > 2. Is there a universal (like above) pointer for procedure|function > > that can point to any kind of procedure|funcion ? > > The short answer, as you've already heard, is No. Well, type System.Address can be used in that fashion. Or you can say "type Void_Star is access all Void;" and use unchecked conversions. So I'd say the answer is "Yes, but you don't usually want to do things this way." > The long answer is that you'll never need these to use Ada. 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. >...In fact, > you'll rarely need pointers at all. I've heard that claim many times in this newsgroup. It doesn't match my experience at all. I use pointers all the time. I just checked one project. About 500 named access types in about a quarter million lines of code. That's about one named access type for every 500 lines of code. Do you call that "rare"? (I didn't count anonymous access types -- there are probably hundreds of those in this project, too.) There are also about 500 packages in this project. You need pointers in Ada whenever you have complex (linked) data structures. Also, whenever you don't know the size of an object at the point it is created. Also, whenever the size of an object changes wildly over time. And whenever you have recursive types. (E.g. in a compiler, an expression contains subexpressions; in Ada you will need pointers to accomplish that, since you can't do it directly.) And whenever you want to pass a composite type as a discriminant -- you have to create a bogus pointer: type T(Some_Task: access Some_Task_Type) is ... (because "Some_Task: Some_Task_Type" is annoyngly illegal. 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. It is true that C requires or encourages pointers in cases where Ada does not. Two examples: (1) a common idiom in C is to loop through an array using a pointer. In Ada, you would use an index instead (which you can also do in C). (2) In C, you need to use heap allocation if a struct contains a field whose size is not known at compiler time. In Ada, you could use a discriminated record instead. 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. >... If you think you do, especially for > beginning Ada, then you're probably misunderstanding something. 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. > About the only time you'd need anything like these is when interfacing > to C. Judging from your questions, I suspect your understanding of Ada > is not yet at a level where you should be doing that. Well, a programmer coming from C might well have some C code lying around, and might well want to call it from Ada! - Bob
From: Robert A Duff on 27 Oct 2005 10:14 Szymon Guz <alpha(a)skynet.org.pl_WITHOUT> writes: > Well, that's how I thought but I wanted to ask. The problem that I want > to solve is how to create a property in type like that ones in > Delphi|Builder, so I have defined the property name, value, read and > write functions. I thought that it could be done by defining a generic > structure like this: > > Name > Value > Get_Function > Set_Function > > when Value is a pointer to value, Get and Set are pointers to function > for setting and getting the value. That's why I thought about universal > variable pointer. I'm not sure I fully understand what you're trying to do, but I suspect you can do it with a hierarchy of tagged types. You will have an access-to-class-wide type, which is sort of like "void *", but it's safe. Alternatively, a generic package might do what you want. You would have one instance for each type of Value you want to store. This method might be safer, but less flexible. - Bob
From: Marc A. Criley on 27 Oct 2005 11:13
Robert A Duff wrote: > "Jeffrey R. Carter" <spam(a)spam.com> writes: > >>...In fact, >>you'll rarely need pointers at all. > > I've heard that claim many times in this newsgroup. It doesn't match my > experience at all. I use pointers all the time. 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. 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. -- Marc A. Criley -- McKae Technologies -- www.mckae.com -- DTraq - XPath In Ada - XML EZ Out |