comp.lang.ada
 help / color / mirror / Atom feed
* Re: HELP:Declaration in ADA?!!
  1996-03-25  0:00 HELP:Declaration in ADA?!! Tuyet-Tram DANG-NGOC
  1996-03-25  0:00 ` Laurent Guerby
@ 1996-03-25  0:00 ` Robert Dewar
  1996-03-28  0:00 ` Ken Devlin
  1996-04-08  0:00 ` Ken Devlin
  3 siblings, 0 replies; 13+ messages in thread
From: Robert Dewar @ 1996-03-25  0:00 UTC (permalink / raw)


Tuyet asks

"DOES SOMEONE KNOW HOW TO DECLARE LONG_INTEGER IN ADA?
All the books I've read here does not answer this metaphysical question, they
just take it as if everyone should know how to declare it. In a wonderful
book, I've seen how to declare LONG_REAL by typing:
   type LONG_REAL is DIGIT 14;
But how to do it for LONG_INTEGER?"

I cannot believe there is ANY Ada book that does not answer this simple 
question, just say

  type x is range m .. n;

where m and n are the bounds you want. If the compiler supports it, that
will do it, and if not, you are out of luck. FOr instane, in GNAT, support
for at least 64 bits is guaranteed, so

  type x is range -2**63 .. 2**63-1;

will always work (actually in GNAT the type Long_Long_Integer, which is
predefined, will always be at least 64 bits).





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

* HELP:Declaration in ADA?!!
@ 1996-03-25  0:00 Tuyet-Tram DANG-NGOC
  1996-03-25  0:00 ` Laurent Guerby
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Tuyet-Tram DANG-NGOC @ 1996-03-25  0:00 UTC (permalink / raw)


Hi there,

I have a stupid question to ask.
DOES SOMEONE KNOW HOW TO DECLARE LONG_INTEGER IN ADA?
All the books I've read here does not answer this metaphysical question, they
just take it as if everyone should know how to declare it. In a wonderful
book, I've seen how to declare LONG_REAL by typing:
   type LONG_REAL is DIGIT 14;
But how to do it for LONG_INTEGER?
Can someone answers me pleeeeaaaase, i've a big and horrible project to finish
for very soon.

Thank you very much for having paid attention to my question, and thank you
very very much if you reply.
                      TRAM
-- 
Tuyet Tram DANG NGOC
Licence d'informatique
Universite de Versailles
dangngoc@ens-info.uvsq.fr
http://www.ens-info.uvsq.fr:8000/public/dangngoc/index.html





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

* Re: HELP:Declaration in ADA?!!
  1996-03-25  0:00 HELP:Declaration in ADA?!! Tuyet-Tram DANG-NGOC
@ 1996-03-25  0:00 ` Laurent Guerby
  1996-03-25  0:00 ` Robert Dewar
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 13+ messages in thread
From: Laurent Guerby @ 1996-03-25  0:00 UTC (permalink / raw)


Tuyet-Tram DANG-NGOC writes
: 
: Hi there,
: 
: I have a stupid question to ask.
: DOES SOMEONE KNOW HOW TO DECLARE LONG_INTEGER IN ADA?

with Text_IO; 
procedure Very_Long is

   The_Bigger_Absolute_Number_I_Want : constant := 999_999_999_999_999;

   type My_Very_Long_Integer is range 
      -The_Bigger_Absolute_Number_I_Want .. 
      +The_Bigger_Absolute_Number_I_Want;

   X : My_Very_Long_Integer := The_Bigger_Absolute_Number_I_Want / 2;

begin
   Text_IO.Put_Line (My_Very_Long_Integer'Image (X));
end Very_Long;

   With GNAT 3.01 on Solaris (it will also work in Ada 83) :

bash$ gnatmake very_long
gcc -c very_long.adb
gnatbind very_long.ali
gnatbl very_long.ali -linkonly
bash$ ./very_long
 499999999999999
bash$

: All  the books   I've read here   does  not answer  this  metaphysical
: question, they just take it as if  everyone should know how to declare
: it. In a wonderful book, I've seen how to declare LONG_REAL by typing:
:   type LONG_REAL is DIGIT 14;
: But how to do it for LONG_INTEGER?

   It must be on your book,  near the page number 1,  how to declare a
constrained integer type.

: Can someone answers me pleeeeaaaase, i've a big and horrible project
: to finish
                                              ^^^^^^^^^^^^^^^^
: for very soon.

   If you don't know the basic of Ada  (yes type X is  range A .. B is
one of Ada's basis), it's hard to achieve a big project in another way
than horrible. Also true for any language X.

: Thank you very much for having paid attention to my question, and thank you
: very very much if you reply.
:                       TRAM

: -- 
: Tuyet Tram DANG NGOC
: Licence d'informatique
: Universite de Versailles
: dangngoc@ens-info.uvsq.fr
: http://www.ens-info.uvsq.fr:8000/public/dangngoc/index.html

-- 
--  Laurent Guerby, student at Telecom Bretagne (France), Team Ada
--  "Use the Source, Luke. The Source will be with you, always (GPL)"
--  http://www-eleves.enst-bretagne.fr/~guerby/ (GATO Project)
--  Try GNAT, the GNU Ada 95 compiler (ftp://cs.nyu.edu/pub/gnat)




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

* Re: HELP:Declaration in ADA?!!
@ 1996-03-25  0:00 tmoran
  0 siblings, 0 replies; 13+ messages in thread
From: tmoran @ 1996-03-25  0:00 UTC (permalink / raw)


>DOES SOMEONE KNOW HOW TO DECLARE LONG_INTEGER IN ADA?
  type LONG_INTEGER is range -2**31 .. 2**31-1; -- or whatever
That might be appropriate, say, if you are doing something with
mathematical number theory.  If you are dealing with distances
or high voltage power lines then
  type meters is range -1_000_000 .. 1_000_000;
  type Volts is range -500_000 .. 500_000;
might be more appropriate names than 'Long_Integer'.




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

* Re: HELP:Declaration in ADA?!!
  1996-03-25  0:00 HELP:Declaration in ADA?!! Tuyet-Tram DANG-NGOC
  1996-03-25  0:00 ` Laurent Guerby
  1996-03-25  0:00 ` Robert Dewar
@ 1996-03-28  0:00 ` Ken Devlin
  1996-04-08  0:00 ` Ken Devlin
  3 siblings, 0 replies; 13+ messages in thread
From: Ken Devlin @ 1996-03-28  0:00 UTC (permalink / raw)


Tuyet-Tram DANG-NGOC <dangngoc@ens-info.uvsq.fr> wrote:

>Hi there,

>I have a stupid question to ask.
>DOES SOMEONE KNOW HOW TO DECLARE LONG_INTEGER IN ADA?
>All the books I've read here does not answer this metaphysical question, they
>just take it as if everyone should know how to declare it. In a wonderful
>book, I've seen how to declare LONG_REAL by typing:
>   type LONG_REAL is DIGIT 14;
>But how to do it for LONG_INTEGER?
>Can someone answers me pleeeeaaaase, i've a big and horrible project to finish
>for very soon.

I must be missing something here.  Isn't this a compiler dependant
question???

I use an (old) Telesoft compiler targeted to M68030 (V4.1B) and VaxVMS
(V3.23)  in both cases LONG_INTEGER  is type that defines a 32 bit
"bucket".  INTEGER, NATURAL, POSITIVE are all 16 bit types.  On the
other hand the Dec ADA compiler I used 3-4 years ago defined INTEGER
to be a 32 bit type and SHORT_INTEGER to be a 16 bit type (I think it
also had LONG_INTEGER as a 64 bit type)

These are predefined types in the compiler.

As I have no experience with compilers that are not hosted on a
VAX,... I repeat, have I missed something???

I'm looking forward to being educated.

										kbd


>Thank you very much for having paid attention to my question, and thank you
>very very much if you reply.
>                      TRAM
>-- 
>Tuyet Tram DANG NGOC
>Licence d'informatique
>Universite de Versailles
>dangngoc@ens-info.uvsq.fr
>http://www.ens-info.uvsq.fr:8000/public/dangngoc/index.html







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

* Re: HELP:Declaration in ADA?!!
@ 1996-03-28  0:00 Scott B. Crawford 0131-314-8253
  0 siblings, 0 replies; 13+ messages in thread
From: Scott B. Crawford 0131-314-8253 @ 1996-03-28  0:00 UTC (permalink / raw)


>DOES SOMEONE KNOW HOW TO DECLARE LONG_INTEGER IN ADA?

DEC Ada, package SYSTEM includes the values of various machine constants:

        MAX_INT: constant:= 2**31-1;
        MIN_INT : constant:= -(2**31);

        type INTEGER_32 is range -2_147_483_648 .. 2_147_483_647;
        for INTEGER_32'SIZE use 32;

        type LARGEST_INTEGER is range MIN_INT .. MAX_INT;

Hope this helps.




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

* Re: HELP:Declaration in ADA?!!
  1996-03-25  0:00 HELP:Declaration in ADA?!! Tuyet-Tram DANG-NGOC
                   ` (2 preceding siblings ...)
  1996-03-28  0:00 ` Ken Devlin
@ 1996-04-08  0:00 ` Ken Devlin
  1996-04-09  0:00   ` Walter B. Hollman Sr.
  1996-04-09  0:00   ` Martin C. Martin
  3 siblings, 2 replies; 13+ messages in thread
From: Ken Devlin @ 1996-04-08  0:00 UTC (permalink / raw)


Tuyet-Tram DANG-NGOC <dangngoc@ens-info.uvsq.fr> wrote:

>Hi there,

>I have a stupid question to ask.
>DOES SOMEONE KNOW HOW TO DECLARE LONG_INTEGER IN ADA?
>All the books I've read here does not answer this metaphysical question, they
>just take it as if everyone should know how to declare it. In a wonderful
>book, I've seen how to declare LONG_REAL by typing:
>   type LONG_REAL is DIGIT 14;
>But how to do it for LONG_INTEGER?
>Can someone answers me pleeeeaaaase, i've a big and horrible project to finish
>for very soon.

I must be missing something here.  Isn't this a compiler dependant
question???

I use an (old) Telesoft compiler targeted to M68030 (V4.1B) and VaxVMS
(V3.23)  in both cases LONG_INTEGER  is type that defines a 32 bit
"bucket".  INTEGER, NATURAL, POSITIVE are all 16 bit types.  On the
other hand the Dec ADA compiler I used 3-4 years ago defined INTEGER
to be a 32 bit type and SHORT_INTEGER to be a 16 bit type (I think it
also had LONG_INTEGER as a 64 bit type)

These are predefined types in the compiler.

As I have no experience with compilers that are not hosted on a
VAX,... I repeat, have I missed something???

I'm looking forward to being educated.

										kbd


>Thank you very much for having paid attention to my question, and thank you
>very very much if you reply.
>                      TRAM
>-- 
>Tuyet Tram DANG NGOC
>Licence d'informatique
>Universite de Versailles
>dangngoc@ens-info.uvsq.fr
>http://www.ens-info.uvsq.fr:8000/public/dangngoc/index.html







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

* Re: HELP:Declaration in ADA?!!
  1996-04-08  0:00 ` Ken Devlin
  1996-04-09  0:00   ` Walter B. Hollman Sr.
@ 1996-04-09  0:00   ` Martin C. Martin
  1996-04-09  0:00     ` Keith Thompson
  1996-04-18  0:00     ` Daryl Siddon
  1 sibling, 2 replies; 13+ messages in thread
From: Martin C. Martin @ 1996-04-09  0:00 UTC (permalink / raw)


> Tuyet-Tram DANG-NGOC <dangngoc@ens-info.uvsq.fr> wrote:
> 
> >Hi there,
> 
> >I have a stupid question to ask.
> >DOES SOMEONE KNOW HOW TO DECLARE LONG_INTEGER IN ADA?
> >All the books I've read here does not answer this metaphysical question, they
> >just take it as if everyone should know how to declare it. In a wonderful
> >book, I've seen how to declare LONG_REAL by typing:
> >   type LONG_REAL is DIGIT 14;
> >But how to do it for LONG_INTEGER?
> >Can someone answers me pleeeeaaaase, i've a big and horrible project to finish
> >for very soon.

Long_Integer may already be defined in your compiler; the ARM says
it's an optional type, but I think most compilers define it (at least,
if there are assembly instructions which would manipulate such an
integer directly).

If not, you can define it this way:

type Long_Integer is range -2_147_483_647 .. 2_147_483_647

Mind you, I think this will only work if there already is a 32 bit
integer type in your compiler, and if so it's probably already called
Long_Integer.

Martin.




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

* Re: HELP:Declaration in ADA?!!
  1996-04-09  0:00   ` Martin C. Martin
@ 1996-04-09  0:00     ` Keith Thompson
  1996-04-18  0:00     ` Daryl Siddon
  1 sibling, 0 replies; 13+ messages in thread
From: Keith Thompson @ 1996-04-09  0:00 UTC (permalink / raw)


Tuyet-Tram DANG-NGOC <dangngoc@ens-info.uvsq.fr> wrote:

>Hi there,

>I have a stupid question to ask.
>DOES SOMEONE KNOW HOW TO DECLARE LONG_INTEGER IN ADA?
>All the books I've read here does not answer this metaphysical question, they
>just take it as if everyone should know how to declare it. In a wonderful
>book, I've seen how to declare LONG_REAL by typing:
>   type LONG_REAL is DIGIT 14;
>But how to do it for LONG_INTEGER?
>Can someone answers me pleeeeaaaase, i've a big and horrible project to finish
>for very soon.

Probably the "big and horrible project" is either finished or overdue
by now, but I'll jump into the fray anyway.

The type Long_Integer, if it exists, is predefined in package Standard.
Some compilers support a type of this name, some don't.  Of those that
do, not all declare it with the same bounds (though -2**31 .. 2**31-1
is most common).

If the compiler you're using doesn't predeclare Long_Integer, you can
declare your own integer type of that name, but it's almost certainly a
bad idea.  Anyone else reading your code will naturally assume that the
name Long_Integer refers to the predefined type, not to a user-defined
type.  Please don't introduce this kind of confusion if you don't have to.

If your compiler does predeclare Long_Integer, DON'T USE IT!  (Sorry about
the shouting.)  Ada provides excellent facilities for declaring your
own integer types of whatever size and/or range you want, subject to
the limitations of the implementation.  Using Long_Integer directly is
inherently non-portable.  (The Ada 95 standard does recommend providing
a type Long_Integer if the implementation supports a type of at least
32 bits, but this is only a recommendation.)

If you want to declare the longest possible integer type, you can do it
like this:

    type Longest_Integer is range System.Min_Int .. System.Max_Int;

If you want a 32-bit type, assuming 2's-complement hardware, you can do
it like this:

    type Integer_32 is range -2**31 .. 2**31-1;

(or use Interfaces.Integer_32 if it's provided).  (There are ways to
declare this without assuming 2's-complement, but that's beyond the
scope of what I feel like thinking about at the moment.)

The only valid reason I can think of for using Long_Integer directly in
user-level code is if you're trying to port a program from a compiler
that supports Long_Integer to one that doesn't, and the program makes
extensive use of Long_Integer.  In this case, it might be necessary
to declare your own type Long_Integer whose range is compatible with
the range of the predefined Long_Integer on the original compiler.
Do this only if you don't have enough time or other resources to remove
the references to Long_Integer, add lots of apologetic comments to the
type declaration, and wash your hands afterward.  8-)}  Then track down
the person who wrote the original code and make them read this article.

(Note that I specifically said user-level code.  I think the GNAT runtime,
for example, uses Long_Integer directly.  In that context, it's not
unreasonable to depend on the characteristics of the compiler.)

-- 
Keith Thompson (The_Other_Keith) kst@thomsoft.com <*>
TeleSoft^H^H^H^H^H^H^H^H Alsys^H^H^H^H^H Thomson Software Products
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718
This sig uses the word "Exon" in violation of the Communications Decency Act.




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

* Re: HELP:Declaration in ADA?!!
  1996-04-08  0:00 ` Ken Devlin
@ 1996-04-09  0:00   ` Walter B. Hollman Sr.
  1996-04-09  0:00   ` Martin C. Martin
  1 sibling, 0 replies; 13+ messages in thread
From: Walter B. Hollman Sr. @ 1996-04-09  0:00 UTC (permalink / raw)


On Apr 08, 1996 23:02:15 in article <Re: HELP:Declaration in ADA?!!>,
'kdevlin@magicnet.net (Ken Devlin)' wrote: 
 
 
>Tuyet-Tram DANG-NGOC <dangngoc@ens-info.uvsq.fr> wrote: 
> 
>>Hi there, 
> 
>>I have a stupid question to ask. 
>>DOES SOMEONE KNOW HOW TO DECLARE LONG_INTEGER IN ADA? 
>>All the books I've read here does not answer this metaphysical question,
they 
>>just take it as if everyone should know how to declare it. In a wonderful

>>book, I've seen how to declare LONG_REAL by typing: 
>>   type LONG_REAL is DIGIT 14; 
>>But how to do it for LONG_INTEGER? 
>>Can someone answers me pleeeeaaaase, i've a big and horrible project to  
>finish 
>>for very soon. 
> 
>I must be missing something here.  Isn't this a compiler dependant 
>question??? 
> 
>I use an (old) Telesoft compiler targeted to M68030 (V4.1B) and VaxVMS 
>(V3.23)  in both cases LONG_INTEGER  is type that defines a 32 bit 
>"bucket".  INTEGER, NATURAL, POSITIVE are all 16 bit types.  On the 
>other hand the Dec ADA compiler I used 3-4 years ago defined INTEGER 
>to be a 32 bit type and SHORT_INTEGER to be a 16 bit type (I think it 
>also had LONG_INTEGER as a 64 bit type) 
> 
>These are predefined types in the compiler. 
> 
>As I have no experience with compilers that are not hosted on a 
>VAX,... I repeat, have I missed something??? 
> 
>I'm looking forward to being educated. 
> 
>										kbd 
> 
> 
>>Thank you very much for having paid attention to my question, and thank
you 
>>very very much if you reply. 
>>                      TRAM 
>>--  
>>Tuyet Tram DANG NGOC 
>>Licence d'informatique 
>>Universite de Versailles 
>>dangngoc@ens-info.uvsq.fr 
>>http://www.ens-info.uvsq.fr:8000/public/dangngoc/index.html 
> 
> 
> 
-- 
If you know the value of a Long_Integer, and can not find one, then DEFINE
ONE of your own! 
Walter B. Hollman Sr 
 
 
 
 
 
 
 





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

* Re: HELP:Declaration in ADA?!!
  1996-04-09  0:00   ` Martin C. Martin
  1996-04-09  0:00     ` Keith Thompson
@ 1996-04-18  0:00     ` Daryl Siddon
  1996-04-22  0:00       ` John English
  1 sibling, 1 reply; 13+ messages in thread
From: Daryl Siddon @ 1996-04-18  0:00 UTC (permalink / raw)


Martin C. Martin wrote:
> 
> > Tuyet-Tram DANG-NGOC <dangngoc@ens-info.uvsq.fr> wrote:
> >
> > >Hi there,
> >
> > >I have a stupid question to ask.
> > >DOES SOMEONE KNOW HOW TO DECLARE LONG_INTEGER IN ADA?
> > >All the books I've read here does not answer this metaphysical question, they
> > >just take it as if everyone should know how to declare it. In a wonderful
> > >book, I've seen how to declare LONG_REAL by typing:
> > >   type LONG_REAL is DIGIT 14;
> > >But how to do it for LONG_INTEGER?
> > >Can someone answers me pleeeeaaaase, i've a big and horrible project to finish
> > >for very soon.
> 
> Long_Integer may already be defined in your compiler; the ARM says
> it's an optional type, but I think most compilers define it (at least,
> if there are assembly instructions which would manipulate such an
> integer directly).
> 
> If not, you can define it this way:
> 
> type Long_Integer is range -2_147_483_647 .. 2_147_483_647
> 
> Mind you, I think this will only work if there already is a 32 bit
> integer type in your compiler, and if so it's probably already called
> Long_Integer.
> 
> Martin.

The approach we used on a recent large scale production software
development effort was to RESTRICT the use of the Standard types in 
application code, by declaring a uniquely named package "Project_Types"
which had all low-level (compiler implementation defined) types. 
This project must ensure that future maintenance (20 years worth) will 
be relatively easy to adapt to new compliers. This "Project_Types"
package localizes the changes needed when using a different compiler. 
All application types are based upon the "Project_Types" package.

Typical types in "Project_Types" may be:
      type unsigned_integer16 is ...
      type unsigned_integer32 is ...
      type signed_integer16   is ...
      etc. 

Developers make specific decisions about the types their application
code needs based upon the range of values, as opposed to "implementation
defined" ranges (e.g. Standard.Integer).

Disadvantage: The types in this package must be pinned-down very early
              in the project lifecycle, as any change/addition will
              necessitate a recompile for all client units.
              NOTE: As an entry criteria for Code Reviews, no Standard
                    types are allowed; only those from "Project_Types".
                    Prior to code being submitted to an "engineering
                    build," scripts are run to scan for misuse.

Advantage   : It localizes the "compiler implementation defined" types,
              rather than throughout application code.

Hope this helps.

Daryl Siddon (Opinions only mine)




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

* Re: HELP:Declaration in ADA?!!
  1996-04-18  0:00     ` Daryl Siddon
@ 1996-04-22  0:00       ` John English
  1996-04-24  0:00         ` Robert Dewar
  0 siblings, 1 reply; 13+ messages in thread
From: John English @ 1996-04-22  0:00 UTC (permalink / raw)


Daryl Siddon (Daryl.Siddon@cpmx.saic.com) wrote:
:               NOTE: As an entry criteria for Code Reviews, no Standard
:                     types are allowed; only those from "Project_Types".

Hope you don't prevent people using Standard.Boolean and Standard.Character!

-- 
----------------------------------------------------------------------------
John English <je@brighton.ac.uk>, Dept. of Computing, University of Brighton
  "Disks are divided into sex and tractors..."
----------------------------------------------------------------------------




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

* Re: HELP:Declaration in ADA?!!
  1996-04-22  0:00       ` John English
@ 1996-04-24  0:00         ` Robert Dewar
  0 siblings, 0 replies; 13+ messages in thread
From: Robert Dewar @ 1996-04-24  0:00 UTC (permalink / raw)


"Daryl Siddon (Daryl.Siddon@cpmx.saic.com) wrote:
:               NOTE: As an entry criteria for Code Reviews, no Standard
:                     types are allowed; only those from "Project_Types"."

Interesting, so this means you cannot use Standard.String (since its index
type is Standard.Integer, which is surely on your verboten list). That
means you cannot use Text_IO.





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

end of thread, other threads:[~1996-04-24  0:00 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-03-25  0:00 HELP:Declaration in ADA?!! Tuyet-Tram DANG-NGOC
1996-03-25  0:00 ` Laurent Guerby
1996-03-25  0:00 ` Robert Dewar
1996-03-28  0:00 ` Ken Devlin
1996-04-08  0:00 ` Ken Devlin
1996-04-09  0:00   ` Walter B. Hollman Sr.
1996-04-09  0:00   ` Martin C. Martin
1996-04-09  0:00     ` Keith Thompson
1996-04-18  0:00     ` Daryl Siddon
1996-04-22  0:00       ` John English
1996-04-24  0:00         ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1996-03-25  0:00 tmoran
1996-03-28  0:00 Scott B. Crawford 0131-314-8253

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