comp.lang.ada
 help / color / mirror / Atom feed
* A question about v'range...?
@ 1997-01-08  0:00 eranshap
  1997-01-09  0:00 ` fd
  0 siblings, 1 reply; 4+ messages in thread
From: eranshap @ 1997-01-08  0:00 UTC (permalink / raw)




Hi All,

I have the following program:

--BEGINNING OF PROGRAM

with Ada.Text_IO;
procedure taskmain is
  NUM_OF_ELEMENTS : constant Integer := 100;
  NUM_OF_TASKS : constant Integer := 10;
  
  type array_type is array (Integer range <>) of Positive;
  
  procedure Find_primes (vector : in array_type; num : in Positive) is
    
    task Manage;
    
    task body Manage is
      ind : Positive;
    begin
      for k in vector'range loop
        ind := k mod num; 
        Ada.Text_IO.Put_line (positive'image (k));
        Ada.Text_IO.Put_line (integer'image (vector'first));
        Ada.Text_IO.Put_line (integer'image (vector'last));
      end loop;
    end Manage;
    
  begin    -- of Procedure find_primes
    null;
  end Find_primes;
  
  vect : array_type(1..NUM_OF_ELEMENTS);
  
begin  -- of procedure taskmain
  for inc in vect'range loop
    vect(inc) := inc;
  end loop;
  Find_primes (vect, NUM_OF_TASKS);
end;

--END OF PROGRAM

And I get this output:

 1
 1
 100
 2
 1
 100
 3
 1
 100
 4
 1
 100
 5
 1
 100
 6
 1
 100
 7
 1
 100
 8
 1
 100
 9
 1
 100

This means that vector'range inside the task Manage is 1..9, while
vector'first is 1, and vector'last is 100, as printed.

I can also add, that when I did the same printing with the taskmain
procedure, it computed it correctly, i.e. vect'range is 1..100.

Why does this happen?

What can I do to correct it?






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

* Re: A question about v'range...?
@ 1997-01-09  0:00 Matthias Oltmanns
  0 siblings, 0 replies; 4+ messages in thread
From: Matthias Oltmanns @ 1997-01-09  0:00 UTC (permalink / raw)



The problem is not the vector'range inside the task. The loop will iterate
through 1 .. 100, but you get a CONSTRAINT ERROR after the 10. iteration.
Take a look at the line

  ind := k mod num; -- (num=10)

For k= 10, 20, ... the expression evaluates to zero, but the variable 'ind' is
of type Positive.
You should spend the variable 'ind' the type Natural and all work fine.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Matthias Oltmanns                    Daimler-Benz Aerospace
                                       Dornier
  - - - - - - - - - -                  Information and
  Tel: +49 7545 8 5683                 Communication Systems
  FAX: +49 7545 8 4504
  email: Oltmanns@vfmail.dofn.de
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




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

* Re: A question about v'range...?
  1997-01-08  0:00 eranshap
@ 1997-01-09  0:00 ` fd
  0 siblings, 0 replies; 4+ messages in thread
From: fd @ 1997-01-09  0:00 UTC (permalink / raw)



eranshap@netvision.net.il wrote:

: Hi All,

: I have the following program:

: --BEGINNING OF PROGRAM

: with Ada.Text_IO;
: procedure taskmain is
:   NUM_OF_ELEMENTS : constant Integer := 100;
:   NUM_OF_TASKS : constant Integer := 10;
:   
:   type array_type is array (Integer range <>) of Positive;
:   
:   procedure Find_primes (vector : in array_type; num : in Positive) is
:     
:   ......

: --END OF PROGRAM

: And I get this output:

:  1
:  1
:  100
:  2
:  1
:  100
:  3
:  1
:  100
:  4
:  1
: ............

: This means that vector'range inside the task Manage is 1..9, while
: vector'first is 1, and vector'last is 100, as printed.

: I can also add, that when I did the same printing with the taskmain
: procedure, it computed it correctly, i.e. vect'range is 1..100.

: Why does this happen?

: What can I do to correct it?

I think you've got a problem with your Ada developpment system, the code that has been generated looks false, this is not normal. There is no Ada Standard explanation.

--
     \\\|||///     DULUC Franck
   .  =======   
  / \| O   O |     Aerospatiale / IRIT
  \ / \`___'/   
   #   _| |_       franck.duluc@avions.aerospatiale.fr
  (#) (     )
   #\//|* *|\\     Tel: 33 - 05 61 18 19 16 
   #\/(  *  )/
   #   =====       Fax: 33 - 05 61 93 86 04
   #   ( _ )
   #   || ||       316, route de Bayonne. 31060 TOULOUSE Cedex 03
  .#---'| |`----.
  `#----' `-----'  FRANCE




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

* Re: A question about v'range...?
@ 1997-01-16  0:00 Matthias Oltmanns
  0 siblings, 0 replies; 4+ messages in thread
From: Matthias Oltmanns @ 1997-01-16  0:00 UTC (permalink / raw)



Franck Duluc wrote:
> You are probably right, since such a behaviour make the task dead and
> the exception is not propagated. But how do you explain that he said
> that the output is correct when it takes place in the main procedure.

I think that the erroneous statement was omitted in the main procedure. But
that is only speculative, all that we can do is to ask Eran.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Matthias Oltmanns                    Daimler-Benz Aerospace
                                       Dornier
  - - - - - - - - - -                  Information and
  Tel: +49 7545 8 5683                 Communication Systems
  FAX: +49 7545 8 4504
  email: Oltmanns@vfmail.dofn.de
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




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

end of thread, other threads:[~1997-01-16  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-01-16  0:00 A question about v'range...? Matthias Oltmanns
  -- strict thread matches above, loose matches on Subject: below --
1997-01-09  0:00 Matthias Oltmanns
1997-01-08  0:00 eranshap
1997-01-09  0:00 ` fd

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