comp.lang.ada
 help / color / mirror / Atom feed
* Beginner's questions
@ 1999-05-02  0:00 Marco Schmidt
  1999-05-02  0:00 ` Matthew Heaney
                   ` (3 more replies)
  0 siblings, 4 replies; 22+ messages in thread
From: Marco Schmidt @ 1999-05-02  0:00 UTC (permalink / raw)


I have to write my first longer program in Ada and could resolve all
questions except for those two using the reference manual. Maybe
someone could help me here... I'm using GNAT 3.11p for NT.

1) I couldn't find out how to use bitwise operations "and" and "or"
(which would be "and" / "or" in Pascal and "&" / "|" in C). Do I have
to include a certain package?

2) I want to use a fixed-size array of constant strings to store some
names which do not all have the same length, but no name is longer
than 20 characters. My approach looks like this:

  type t_my_array is array(0..17) of String;

  names : constant t_my_array := ("string 1", "string 2", ...,
    "string 18");

The compiler doesn't like this (unconstrained element type). If I
replace String with String(0..19), it is compiled, but a runtime error
is raised. How should I do it?

Thanks in advance,
Marco




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Beginner's questions
  1999-05-02  0:00 Beginner's questions Marco Schmidt
@ 1999-05-02  0:00 ` Matthew Heaney
  1999-05-03  0:00   ` Marco Schmidt
  1999-05-03  0:00 ` Andreas Winckler
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 22+ messages in thread
From: Matthew Heaney @ 1999-05-02  0:00 UTC (permalink / raw)


marcoschmidt@geocities.com (Marco Schmidt) writes:

> 1) I couldn't find out how to use bitwise operations "and" and "or"
> (which would be "and" / "or" in Pascal and "&" / "|" in C). Do I have
> to include a certain package?

Those operations predefined for all modular types.  Were you using an
integer type?


> 2) I want to use a fixed-size array of constant strings to store some
> names which do not all have the same length, but no name is longer
> than 20 characters. My approach looks like this:
> 
>   type t_my_array is array(0..17) of String;
> 
>   names : constant t_my_array := ("string 1", "string 2", ...,
>     "string 18");
> 
> The compiler doesn't like this (unconstrained element type). If I
> replace String with String(0..19), it is compiled, but a runtime error
> is raised. How should I do it?


You could use an instantation of
Ada.Strings.Bounded.Generic_Bounded_Length.

Or you could use Ada.Strings.Unbounded.

Or you could use a discriminated record:

  subtype Name_Length_Range is Natural range 0 .. 20;

  type Name_Buffer (Length : Name_Length_Range := 0) is
    record
        Name : String (1 .. Length);
    end record;

  function "+" (R : String) return Name_Buffer is
  begin
    return (R'length, R);
  end;

  type Name_Array is array (Positive range <>) of Name_Buffer;

  Names : Name_Array :=
    (+"Heckle",
     +"Jeckle",
     +"Marvelous",
     +"Magpies",
     +"Let's have some fun",
     +"With name arrays");



      




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Beginner's questions
  1999-05-02  0:00 Beginner's questions Marco Schmidt
  1999-05-02  0:00 ` Matthew Heaney
@ 1999-05-03  0:00 ` Andreas Winckler
  1999-05-03  0:00   ` Matthew Heaney
  1999-05-03  0:00 ` dennison
  1999-05-04  0:00 ` czgrr
  3 siblings, 1 reply; 22+ messages in thread
From: Andreas Winckler @ 1999-05-03  0:00 UTC (permalink / raw)



Marco Schmidt wrote:

> 2) I want to use a fixed-size array of constant strings to store some
> names which do not all have the same length, but no name is longer
> than 20 characters. My approach looks like this:
> 
>   type t_my_array is array(0..17) of String;
> 
>   names : constant t_my_array := ("string 1", "string 2", ...,
>     "string 18");
> 
> The compiler doesn't like this (unconstrained element type). If I
> replace String with String(0..19), it is compiled, but a runtime error
> is raised. How should I do it?

For programmers used to Pascal the strings in Ada can be really
irritating, at least it was for me. I usually use unbounded strings
which are comparable to the strings in Pascal.


Greetings,

AW
-- 
------------------------------------------------------------------------
Andreas Winckler
Dipl.ing.
Software Engineering

FREQUENTIS Network Systems GmbH
Department MHS
Bahnhofsplatz 1
88045 Friedrichshafen
Tel: (+49) (7541) 282 - 462  Fax: (+49) (7541) 282 - 299
http://www.frqnet.de




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Beginner's questions
  1999-05-03  0:00 ` Andreas Winckler
@ 1999-05-03  0:00   ` Matthew Heaney
  1999-05-03  0:00     ` Andreas Winckler
  0 siblings, 1 reply; 22+ messages in thread
From: Matthew Heaney @ 1999-05-03  0:00 UTC (permalink / raw)


Andreas Winckler <andreas.winckler@frqnet.de> writes:
> For programmers used to Pascal the strings in Ada can be really
> irritating, at least it was for me. I usually use unbounded strings
> which are comparable to the strings in Pascal.

A discriminated record is closer to the Pascal approach.  

I don't recommend using a heap-based solution (type Unbounded_String)
unless you have a compelling need to.

Jean-Pierre Rosen has written a nice variable-length string package:

(start of excerpt from documentation)
What package Variable_Length does

This package provides a simple "variable length string" type. It is
useful when you just want to store strings whose maximum length is known
beforehand. It provides operations that are consistent with those
defined in the Bounded_String and Unbounded_String packages.
(end of excerpt from documentation)

You can get it from the Adalog web page:

<http://perso.wanadoo.fr/adalog/compo2.htm>





^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Beginner's questions
  1999-05-03  0:00   ` Matthew Heaney
@ 1999-05-03  0:00     ` Andreas Winckler
  1999-05-03  0:00       ` David Starner
  0 siblings, 1 reply; 22+ messages in thread
From: Andreas Winckler @ 1999-05-03  0:00 UTC (permalink / raw)



Matthew Heaney wrote:

> I don't recommend using a heap-based solution (type Unbounded_String)
> unless you have a compelling need to.

Why? Where's the problem with it? Because high availability is an issue
for me I would be interested in details.

> Jean-Pierre Rosen has written a nice variable-length string package:

Already downloaded it, looks good. Thanks for the hint.

Greetings,

AW
-- 
------------------------------------------------------------------------
Andreas Winckler
Dipl.ing.
Software Engineering

FREQUENTIS Network Systems GmbH
Department MHS
Bahnhofsplatz 1
88045 Friedrichshafen, Germany
Tel: (+49) (7541) 282 - 462  Fax: (+49) (7541) 282 - 299
http://www.frqnet.de




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Beginner's questions
  1999-05-02  0:00 ` Matthew Heaney
@ 1999-05-03  0:00   ` Marco Schmidt
  1999-05-03  0:00     ` Matthew Heaney
  0 siblings, 1 reply; 22+ messages in thread
From: Marco Schmidt @ 1999-05-03  0:00 UTC (permalink / raw)


On Sun, 02 May 1999 19:15:01 GMT, Matthew Heaney
<matthew_heaney@acm.org> wrote:

Thanks for your answer.

>> 1) I couldn't find out how to use bitwise operations "and" and "or"
>> (which would be "and" / "or" in Pascal and "&" / "|" in C). Do I have
>> to include a certain package?
>
>Those operations predefined for all modular types.  Were you using an
>integer type?

Yes, but I want to use "and" and "or" for bitwise manipulation, not
logical operations which evaluate to boolean. I want to fill an array
of 64 Integer values with the number of "on" bits in the numbers 0 to
63, so the resulting array should look like this:

index : value
-------------
0 : 0
1 : 1
2 : 1
3 : 2
4 : 1
5 : 2
and so on. It's a lookup table I want to use in another part of the
program.

In Pascal, logical and bitwise operators have the same name (and /
or), while there are different operators in C, C++ and Java (& and &&,
| and ||). I need the & and | version.

Regards,
Marco




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Beginner's questions
  1999-05-03  0:00   ` Marco Schmidt
@ 1999-05-03  0:00     ` Matthew Heaney
  0 siblings, 0 replies; 22+ messages in thread
From: Matthew Heaney @ 1999-05-03  0:00 UTC (permalink / raw)


marcoschmidt@geocities.com (Marco Schmidt) writes:

> >Those operations predefined for all modular types.  Were you using an
> >integer type?
> 
> Yes, but I want to use "and" and "or" for bitwise manipulation, not
> logical operations which evaluate to boolean. 

I don't understand this answer.

"and", "or", "xor", and "not" for a modular type are bitwise operators
that return a modular value, not Boolean.  

"and" and "or" aren't defined for (signed) integer types.

What kind of type type were you using?

Why isn't a modular type adequate?


> In Pascal, logical and bitwise operators have the same name (and /
> or), while there are different operators in C, C++ and Java (& and &&,
> | and ||). I need the & and | version.

Signed integer types in Ada95 have neither logical nor bitwise
operators.

Modular (unsigned) types in Ada95 have bitwise operators "and" and
"or".  They are not logical operators.

There is a way to define bitwise operators for a signed integer type,
but it's not going to be as efficient as using an unsigned type.







^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Beginner's questions
  1999-05-02  0:00 Beginner's questions Marco Schmidt
  1999-05-02  0:00 ` Matthew Heaney
  1999-05-03  0:00 ` Andreas Winckler
@ 1999-05-03  0:00 ` dennison
  1999-05-04  0:00   ` Tucker Taft
  1999-05-04  0:00 ` czgrr
  3 siblings, 1 reply; 22+ messages in thread
From: dennison @ 1999-05-03  0:00 UTC (permalink / raw)


In article <372da49c.12366381@news.rwth-aachen.de>,
  marcoschmidt@geocities.com wrote:
> I have to write my first longer program in Ada and could resolve all
> questions except for those two using the reference manual. Maybe
> someone could help me here... I'm using GNAT 3.11p for NT.
>
> 1) I couldn't find out how to use bitwise operations "and" and "or"
> (which would be "and" / "or" in Pascal and "&" / "|" in C). Do I have
> to include a certain package?

There are two ways to perform bitwise operations. One way is to use modular
types, and the other is to use packed arrays of booleans. Which one is best
for you to use depends on what you want to do with your objects *besides* the
bitwise operations.


> 2) I want to use a fixed-size array of constant strings to store some
> names which do not all have the same length, but no name is longer
..
> is raised. How should I do it?

If you won't need to change the contents of the strings, one quick-and-dirty
method is the following:

type String_Ptr is access String;
type String_Ptr_List is array (1..3) of String_Ptr;
String_List : constant String_Ptr_List :=
   (new String'("Hi there!"),
    new String'("How are you doing?"),
    new String'("Why, I'm fine. How are you?")
   );

Don't do this in a loop or subroutine, unless you are prepared to deallocate
the strings when you are done. But as one-time-only code on an OS that cleans
up process resources after termination this often does the trick for me.

--
T.E.D.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Beginner's questions
  1999-05-03  0:00     ` Andreas Winckler
@ 1999-05-03  0:00       ` David Starner
  1999-05-04  0:00         ` Andreas Winckler
  0 siblings, 1 reply; 22+ messages in thread
From: David Starner @ 1999-05-03  0:00 UTC (permalink / raw)




Andreas Winckler wrote:
> 
> Matthew Heaney wrote:
> 
> > I don't recommend using a heap-based solution (type Unbounded_String)
> > unless you have a compelling need to.
> 
> Why? Where's the problem with it? Because high availability is an issue
> for me I would be interested in details.
 
I believe he was talking about efficency. Dynamic storage allocations (a
superset of heap-based solution) are very inefficent, or at least so my
Fortran 77 teacher says. I would recommend checking to see if it's a
worry before going out of your way in the name of efficency. I
personally have only had one efficency problem, and that ran about
10,000 times too slow due to my mis-estimation of the problem size.
YMMV, especially if you're not a student. 

The only other thing I can think he might have been talking about is
that heap-based solutions are hard to use on embedded systems and stuff
like that, which might be a worry if you're working on those things.




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Beginner's questions
  1999-05-03  0:00 ` dennison
@ 1999-05-04  0:00   ` Tucker Taft
  1999-05-04  0:00     ` dennison
  0 siblings, 1 reply; 22+ messages in thread
From: Tucker Taft @ 1999-05-04  0:00 UTC (permalink / raw)


dennison@telepath.com wrote:

: > 2) I want to use a fixed-size array of constant strings to store some
: > names which do not all have the same length, but no name is longer
: ..
: > is raised. How should I do it?

: If you won't need to change the contents of the strings, one quick-and-dirty
: method is the following:

: type String_Ptr is access String;
                          ^^^ "constant"

: type String_Ptr_List is array (1..3) of String_Ptr;
: String_List : constant String_Ptr_List :=
:    (new String'("Hi there!"),
:     new String'("How are you doing?"),
:     new String'("Why, I'm fine. How are you?")
:    );

: Don't do this in a loop or subroutine, unless you are prepared to deallocate
: the strings when you are done. But as one-time-only code on an OS that cleans
: up process resources after termination this often does the trick for me.

If you use "type String_Ptr is access constant String" to
declare your pointer type, then the language prevents
erroneous overwriting of the strings, and the compiler
(if it follows the Ada 95 implementation advice) will
allocate and initialize the pointed-to strings at link-time, rather than
run-time, exactly like "C" string literals.

: --
: T.E.D.

: -----------== Posted via Deja News, The Discussion Network ==----------
: http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    

--
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Beginner's questions
  1999-05-02  0:00 Beginner's questions Marco Schmidt
                   ` (2 preceding siblings ...)
  1999-05-03  0:00 ` dennison
@ 1999-05-04  0:00 ` czgrr
  1999-05-04  0:00   ` Nick Roberts
  3 siblings, 1 reply; 22+ messages in thread
From: czgrr @ 1999-05-04  0:00 UTC (permalink / raw)


In article <372da49c.12366381@news.rwth-aachen.de>,
  marcoschmidt@geocities.com wrote:
[snip]
> 2) I want to use a fixed-size array of constant strings to store some
> names which do not all have the same length, but no name is longer
> than 20 characters. My approach looks like this:
>
>   type t_my_array is array(0..17) of String;
>
>   names : constant t_my_array := ("string 1", "string 2", ...,
>     "string 18");
>
> The compiler doesn't like this (unconstrained element type). If I
> replace String with String(0..19), it is compiled, but a runtime error
> is raised. How should I do it?
>
> Thanks in advance,
> Marco
Hi Marco.

P.S. I am using Ada83 and don't know Ada95. If you are using the latter, no
doubt someone else here will correct what I might get wrong.

Several perfectly good solutions have already been posted in response to this
message. I have yet another solution, but first...

1. The reason that you are getting the unconstrained element type is that you
cannot declare an array (or indeed a variable) of type STRING without
specifying a length. Constants can be declared, but only because the length is
implicitly determined:
  temp : CONSTANT STRING := "Hello there." ;
In the above example, you could say:
  SUBTYPE string_20 IS STRING ( 1 .. 20 ) ;
  TYPE t_my_array IS ARRAY ( 0 .. 17 ) of string_20 ;
which is essentially the same as your String(0..19) but see below.

2a. The reason that you get the runtime error is that the index to STRING is
POSITIVE. So 'STRING ( 0 .. 19 )' is an error but 'STRING ( 1 .. 20 )' is not,
because 0 is not a positive number (btw, STRING ( 1 .. 0 ) is allowed).

2b. You will also get a runtime error because the strings you are assigning to
the array are not each 20 characters long:
  names : CONSTANT t_my_array :=
    ( "string 1            ",
      "string 2            ",
      ...,
      "string 18           " ) ;

Now, another alternative solution...

When I learned Pascal at University, sometimes the format of the output was
constructed using the knowledge that the strings being printed were a fixed
length. This is useful for printing columns of data, formatted text files,
etc. Now there are other ways of doing this in Ada anyway using TEXT_IO, but
there are also other reasons why strings of fixed lengths are required. You
said yourself in your message that each string is no more than 20 characters
long, so presumably there would be a reason for this.

So an alternative solution is to use the above type declaration for string_20
and a couple of simple functions:

  -- This puts the first 20 characters of text into a string_20 type.
  -- If text is shorter than 20 characters, spaces are added to the end.
  FUNCTION padded_string
             ( text : IN     STRING )
                      RETURN string_20 ;

  -- This removes any trailing spaces from the end of text.
  FUNCTION trunc_string
             ( text : IN     string_20 )
                      RETURN STRING ;

Then, to continue your example, you can do the following:
  names : CONSTANT t_my_array :=
    ( padded_string ( "string 1" ),
      padded_string ( "string 2" ),
      ...
      padded_string ( "string 18" ) ) ;
and perhaps:
  FOR i IN 0 .. 17 LOOP
    TEXT_IO.PUT_LINE
      ( "Orig. String is '" & names ( i ) & "'." ) ;
  END LOOP ;
  FOR i IN 0 .. 17 LOOP
    TEXT_IO.PUT_LINE
      ( "Trunc string is '" & trunc_string ( names ( i ) ) & "'." ) ;
  END LOOP ;

It all depends what you want from the program.

HTH
czgrr

--
My opinions, suggestions, etc, are not necessarily those of my employer.
They might not even be right. Use at your own risk.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Beginner's questions
  1999-05-03  0:00       ` David Starner
@ 1999-05-04  0:00         ` Andreas Winckler
  1999-05-04  0:00           ` Larry Kilgallen
  0 siblings, 1 reply; 22+ messages in thread
From: Andreas Winckler @ 1999-05-04  0:00 UTC (permalink / raw)



David Starner wrote:
> I believe he was talking about efficency. Dynamic storage allocations
> (a superset of heap-based solution) are very inefficent, or at least
> so my Fortran 77 teacher says. I would recommend checking to see if
> it's a worry before going out of your way in the name of efficency.

Well efficency isn't my biggest concern, I fear the deallocation which
may produce memory leaks.

> The only other thing I can think he might have been talking about is
> that heap-based solutions are hard to use on embedded systems and
> stuff like that, which might be a worry if you're working on those
> things.

Not embedded systems but message handling systems for air traffic
control which are designed for 99,995% availability. This means
rebooting maximum once a year, not twice a day like with M$-Windows.

So, does anybody know more details about unbounded_strings? How does it
work? Does it recycle deallocated memory by 100%? If not I'll better
stay away from it.


Greetings,

AW
-- 
------------------------------------------------------------------------
Andreas Winckler
Dipl.ing.
Software Engineering

FREQUENTIS Network Systems GmbH
Department MHS
Bahnhofsplatz 1
88045 Friedrichshafen, Germany
Tel: (+49) (7541) 282 - 462  Fax: (+49) (7541) 282 - 299
http://www.frqnet.de




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Beginner's questions
  1999-05-04  0:00         ` Andreas Winckler
@ 1999-05-04  0:00           ` Larry Kilgallen
  1999-05-04  0:00             ` Martin C. Carlisle
  0 siblings, 1 reply; 22+ messages in thread
From: Larry Kilgallen @ 1999-05-04  0:00 UTC (permalink / raw)


In article <372ED1C4.9A1AE1B2@frqnet.de>, Andreas Winckler <andreas.winckler@frqnet.de> writes:

> Not embedded systems but message handling systems for air traffic
> control which are designed for 99,995% availability. This means
> rebooting maximum once a year, not twice a day like with M$-Windows.
> 
> So, does anybody know more details about unbounded_strings? How does it
> work? Does it recycle deallocated memory by 100%? If not I'll better
> stay away from it.

There are three levels of guarantee possible:

	The language specification (reference manual) might require it.

	The author of your compiler(s) might commit to it.

	You might engage in testing for it.

Of these the first is probably least important other than as a nudge
to the second.

Larry Kilgallen




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Beginner's questions
  1999-05-04  0:00   ` Tucker Taft
@ 1999-05-04  0:00     ` dennison
  1999-05-10  0:00       ` Tucker Taft
  0 siblings, 1 reply; 22+ messages in thread
From: dennison @ 1999-05-04  0:00 UTC (permalink / raw)


In article <FB6yDx.53x.0.-s@inmet.camb.inmet.com>,
  stt@houdini.camb.inmet.com (Tucker Taft) wrote:
> dennison@telepath.com wrote:
>
> : If you won't need to change the contents of the strings, one quick-and-dirty
> : method is the following:
>
> : type String_Ptr is access String;
>                           ^^^ "constant"
>
> If you use "type String_Ptr is access constant String" to
> declare your pointer type, then the language prevents
> erroneous overwriting of the strings, and the compiler
> (if it follows the Ada 95 implementation advice) will
> allocate and initialize the pointed-to strings at link-time, rather than
> run-time, exactly like "C" string literals.

Ohhhhh, nifty! That was effectively an Ada 83 code chunk I posted. I'll have
to remember to use "access constant" next time it comes up.

Does your last sentence only apply for package specs and bodies, not for
subprograms? When I use this trick, its typically in my "main" subprogram.

--
T.E.D.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Beginner's questions
  1999-05-04  0:00           ` Larry Kilgallen
@ 1999-05-04  0:00             ` Martin C. Carlisle
  1999-05-04  0:00               ` Larry Kilgallen
  0 siblings, 1 reply; 22+ messages in thread
From: Martin C. Carlisle @ 1999-05-04  0:00 UTC (permalink / raw)


Unbounded strings are required not to leak memory.  See A.4.5(88)
"No storage associated with an Unbounded_String object shall be lost upon
assignment or scope exit."

This sentence immediately reminds me of Ada.Finalization.Controlled, and
not suprisingly, GNAT uses controlled types to implement unbounded
strings.  I have not checked ACVC, but I suspect it would be very hard 
to validate a compiler not meeting this requirement.

--Martin

In article <1999May4.093747.1@eisner>,
Larry Kilgallen <Kilgallen@eisner.decus.org.nospam> wrote:
>In article <372ED1C4.9A1AE1B2@frqnet.de>, Andreas Winckler <andreas.winckler@frqnet.de> writes:
>> So, does anybody know more details about unbounded_strings? How does it
>> work? Does it recycle deallocated memory by 100%? If not I'll better
>> stay away from it.
>
>There are three levels of guarantee possible:
>	The language specification (reference manual) might require it.
>	The author of your compiler(s) might commit to it.
>	You might engage in testing for it.
-- 
Martin C. Carlisle, Asst Prof of Computer Science, US Air Force Academy
carlislem@acm.org, http://www.usafa.af.mil/dfcs/bios/carlisle.html
DISCLAIMER:  This content in no way reflects the opinions, standards or 
policy of the US Air Force Academy or the United States Government.




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Beginner's questions
  1999-05-04  0:00             ` Martin C. Carlisle
@ 1999-05-04  0:00               ` Larry Kilgallen
  1999-05-05  0:00                 ` Andreas Winckler
  0 siblings, 1 reply; 22+ messages in thread
From: Larry Kilgallen @ 1999-05-04  0:00 UTC (permalink / raw)


In article <7gn2d5$a8f$1@cnn.Princeton.EDU>, mcc@entropy.cs.princeton.edu (Martin C. Carlisle) writes:
> Unbounded strings are required not to leak memory.  See A.4.5(88)
> "No storage associated with an Unbounded_String object shall be lost upon
> assignment or scope exit."
> 
> This sentence immediately reminds me of Ada.Finalization.Controlled, and
> not suprisingly, GNAT uses controlled types to implement unbounded
> strings.  I have not checked ACVC, but I suspect it would be very hard 
> to validate a compiler not meeting this requirement.

Of course proof that no memory is leaked under ACVC is not proof that
memory could never leak, so I would still urge the poster with the
Air Traffic Control system to test it for memory leaks after it has
been built.  After a plane has crashed seems like the incorrect time
to ask to have the compiler price refunded.

Larry Kilgallen




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Beginner's questions
  1999-05-04  0:00 ` czgrr
@ 1999-05-04  0:00   ` Nick Roberts
  1999-05-07  0:00     ` Robert Dewar
  0 siblings, 1 reply; 22+ messages in thread
From: Nick Roberts @ 1999-05-04  0:00 UTC (permalink / raw)


To add the Ada 95 spin on czgrr's post, the package Ada.Strings.Bounded
provides the functionality proposed.  This package is not usually
implemented using dynamic allocation (the heap).  If using the heap is a
worry, and you can get away with the wasted space associated with the
'padding' at the end of your strings, this package may be the solution you
require.

I continue the question the fashion (for that's what I believe it is) for
Ada implementations not to support garbage collection.  For the vast
majority of string-related applications, the 'inefficiency' of dynamic
allocation---even with a garbage collector, provided it's a half-decent
one---is not a problem.

-------------------------------------
Nick Roberts
-------------------------------------







^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Beginner's questions
  1999-05-04  0:00               ` Larry Kilgallen
@ 1999-05-05  0:00                 ` Andreas Winckler
  0 siblings, 0 replies; 22+ messages in thread
From: Andreas Winckler @ 1999-05-05  0:00 UTC (permalink / raw)



Larry Kilgallen wrote:
> Of course proof that no memory is leaked under ACVC is not proof that
> memory could never leak, so I would still urge the poster with the
> Air Traffic Control system to test it for memory leaks after it has
> been built.

Well, unbounded strings are just an easy way to do some things but in
our application there's no real need for it. Probably the best way is to
follow Matthew's recommendation from some postings ago and resign to use
unbounded strings at all (if possible).

> After a plane has crashed seems like the incorrect time to ask to have
> the compiler price refunded.

Good point. ;-)


Greetings,

AW
-- 
------------------------------------------------------------------------
Andreas Winckler
Dipl.ing.
Software Engineering

FREQUENTIS Network Systems GmbH
Department MHS
Bahnhofsplatz 1
88045 Friedrichshafen, Germany
Tel: (+49) (7541) 282 - 462  Fax: (+49) (7541) 282 - 299
http://www.frqnet.de




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Beginner's questions
  1999-05-04  0:00   ` Nick Roberts
@ 1999-05-07  0:00     ` Robert Dewar
  1999-05-07  0:00       ` David Starner
  0 siblings, 1 reply; 22+ messages in thread
From: Robert Dewar @ 1999-05-07  0:00 UTC (permalink / raw)


In article <373248e7@eeyore.callnetuk.com>,
  "Nick Roberts" <nickroberts@callnetuk.com> wrote:

> I continue the question the fashion (for that's what I believe it is) for
> Ada implementations not to support garbage collection.  For the vast
> majority of string-related applications, the 'inefficiency' of dynamic
> allocation---even with a garbage collector, provided it's a half-decent
> one---is not a problem.

This is nothing to do with fashion, it is to do with user requirements.
All that is needed to make garbage collection appear in GNAT for example
is some customer who really needs it and is willing to fund at least part
of the development cost.

We have a long list of desirable improvements for GNAT. You see a chunk
of this list bitten off for each new release (each GNAT release so far
has had substantial new functionality, and this will continue to be the
case -- you should get to see the 3.12 list very shortly, I already posted
a small preview).

The prioritization of these improvements is driven partly from what we
think will be generally useful, but mostly from customer requirements.

Note that it is perfectly posssible to use any one of several conservative
garbage collectors with GNAT. Indeed, we have delayed using virtual origins
for arrays (one of the improvements on our list, which would noticeably
improve efficiency, especially of Fortran type numeric codes), precisely
because it would be incompatible with such collectors.

Why don't these meet your needs?

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Beginner's questions
  1999-05-07  0:00     ` Robert Dewar
@ 1999-05-07  0:00       ` David Starner
  1999-05-08  0:00         ` ak
  0 siblings, 1 reply; 22+ messages in thread
From: David Starner @ 1999-05-07  0:00 UTC (permalink / raw)




Robert Dewar wrote:
> This is nothing to do with fashion, it is to do with user requirements.
> All that is needed to make garbage collection appear in GNAT for example
> is some customer who really needs it and is willing to fund at least part
> of the development cost.

One thing that may make this easier is that EGCS snapshot now includes a
conservative garbage collector for the Java compiler, so it shouldn't be
that hard to connect GNAT to that garbage collector when it runs on
EGCS. Trying that is on my list for my first EGCS project (hopefull
sometime in the next few years.)

> Note that it is perfectly posssible to use any one of several conservative
> garbage collectors with GNAT. 
Like writing an interface for the Boehem GC for each class? Is there a
better conservative GC to use with Ada, or a more Ada-native interface?

> Indeed, we have delayed using virtual origins
> for arrays (one of the improvements on our list, which would noticeably
> improve efficiency, especially of Fortran type numeric codes), precisely
> because it would be incompatible with such collectors.
Thanks. I appreciate it.
 
> Why don't these meet your needs?
Because we're lazy, and it's much easier just to set a compiler switch.
Also, the documentation offers no clues that it is safe to use such
garbage collectors. It would be nice to have a statement in the compiler
docs that it should be fairly safe to use a conservative garbage
collector.




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Beginner's questions
  1999-05-07  0:00       ` David Starner
@ 1999-05-08  0:00         ` ak
  0 siblings, 0 replies; 22+ messages in thread
From: ak @ 1999-05-08  0:00 UTC (permalink / raw)


In article <37332A6D.B0D02309@aasaa.ofe.org>,
David Starner <dstarner98@aasaa.ofe.org> writes:
> Robert Dewar wrote:
>> This is nothing to do with fashion, it is to do with user requirements.
>> All that is needed to make garbage collection appear in GNAT for example
>> is some customer who really needs it and is willing to fund at least part
>> of the development cost.

> One thing that may make this easier is that EGCS snapshot now includes a
> conservative garbage collector for the Java compiler, so it shouldn't be
> that hard to connect GNAT to that garbage collector when it runs on
> EGCS. Trying that is on my list for my first EGCS project (hopefull
> sometime in the next few years.)

I only see a slightly hacked version of the Boehm GC in the libgcj repository.
The egcs CVS server seems to also carry a separate "egcs_gc_branch" where some 
experimental work is going on to replace some of the obstack usage in gcc with a GC
scheme. 

Both things are not very helpful for implementing GC in the Ada runtime I think.

>> Note that it is perfectly posssible to use any one of several conservative
>> garbage collectors with GNAT. 
> Like writing an interface for the Boehem GC for each class? Is there a
> better conservative GC to use with Ada, or a more Ada-native interface?

What is wrong with the Boehm GC? 

>> Why don't these meet your needs?
> Because we're lazy, and it's much easier just to set a compiler switch.
> Also, the documentation offers no clues that it is safe to use such
> garbage collectors. It would be nice to have a statement in the compiler
> docs that it should be fairly safe to use a conservative garbage
> collector.

With the conservative boehm gc it would most likely be only a "-lgc" switch.
 
Of course it could do better with some compiler cooperation, but is there
any strong reason why a conservative GC cannot just be plugged in?

-Andi




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Beginner's questions
  1999-05-04  0:00     ` dennison
@ 1999-05-10  0:00       ` Tucker Taft
  0 siblings, 0 replies; 22+ messages in thread
From: Tucker Taft @ 1999-05-10  0:00 UTC (permalink / raw)


dennison@telepath.com wrote:
> 
> In article <FB6yDx.53x.0.-s@inmet.camb.inmet.com>,
>   stt@houdini.camb.inmet.com (Tucker Taft) wrote:
> > If you use "type String_Ptr is access constant String" to
> > declare your pointer type, then the language prevents
> > erroneous overwriting of the strings, and the compiler
> > (if it follows the Ada 95 implementation advice) will
> > allocate and initialize the pointed-to strings at link-time, rather than
> > run-time, exactly like "C" string literals.
> 
> Ohhhhh, nifty! That was effectively an Ada 83 code chunk I posted. I'll have
> to remember to use "access constant" next time it comes up.
> 
> Does your last sentence only apply for package specs and bodies, not for
> subprograms? When I use this trick, its typically in my "main" subprogram.

It should work in all environments, when the initial value is
known statically.  However, this is just implementation advice,
and I can imagine that some compilers are not yet doing the
right thing.
> 
> --
> T.E.D.
-- 
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA




^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~1999-05-10  0:00 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-05-02  0:00 Beginner's questions Marco Schmidt
1999-05-02  0:00 ` Matthew Heaney
1999-05-03  0:00   ` Marco Schmidt
1999-05-03  0:00     ` Matthew Heaney
1999-05-03  0:00 ` Andreas Winckler
1999-05-03  0:00   ` Matthew Heaney
1999-05-03  0:00     ` Andreas Winckler
1999-05-03  0:00       ` David Starner
1999-05-04  0:00         ` Andreas Winckler
1999-05-04  0:00           ` Larry Kilgallen
1999-05-04  0:00             ` Martin C. Carlisle
1999-05-04  0:00               ` Larry Kilgallen
1999-05-05  0:00                 ` Andreas Winckler
1999-05-03  0:00 ` dennison
1999-05-04  0:00   ` Tucker Taft
1999-05-04  0:00     ` dennison
1999-05-10  0:00       ` Tucker Taft
1999-05-04  0:00 ` czgrr
1999-05-04  0:00   ` Nick Roberts
1999-05-07  0:00     ` Robert Dewar
1999-05-07  0:00       ` David Starner
1999-05-08  0:00         ` ak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox