comp.lang.ada
 help / color / mirror / Atom feed
* Question on arrays
@ 2002-09-16 11:02 prashna
  2002-09-16 12:03 ` Preben Randhol
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: prashna @ 2002-09-16 11:02 UTC (permalink / raw)


Hi all,
Pls explain what is wrong in this statement?

A_Integer(2) := (others => 2.0);

where A_Integer is an array of integer, whose index is integer ranging
form 1..10.

I am using Tartan compiler on Aix machine and the error is
"segmentation fault (core dumped)"
Thanks in Advance.



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

* Re: Question on arrays
  2002-09-16 11:02 Question on arrays prashna
@ 2002-09-16 12:03 ` Preben Randhol
  2002-09-16 19:15   ` tmoran
  2002-09-16 12:08 ` Marin David Condic
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Preben Randhol @ 2002-09-16 12:03 UTC (permalink / raw)


On 16 Sep 2002 04:02:44 -0700, prashna wrote:
> Hi all,
> Pls explain what is wrong in this statement?
> 
> A_Integer(2) := (others => 2.0);
                             ^^^
                             Isn't this a real and you have integers in
                             the array. Does Tartan allow you to compile
                             this?

Anyway the problem with the statment above is that you are trying to put
the composite type from (other => 2) into the array at the second
element. Here you can only put a integer.

I assume you have a simple array like:

type A_Integer_Type is array (1..10) of Integer;
A_Integer : A_Integer_Type;

So please explain a bit more what you are trying to do here and also
read:

   http://www.it.bton.ac.uk/staff/je/adacraft/ch06.htm
   and
   http://goanna.cs.rmit.edu.au/~dale/ada/aln/6_arrays.html

An example program:

procedure t is

      type A_Integer_Type is array (1..10) of integer;
      A_Integer : A_Integer_Type;

begin
   -- Now I want to put the interger 5 in the array place 2 and 1 in all
   -- the others.
    A_Integer := (2 => 5, others => 1);
end t;



Preben



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

* Re: Question on arrays
  2002-09-16 11:02 Question on arrays prashna
  2002-09-16 12:03 ` Preben Randhol
@ 2002-09-16 12:08 ` Marin David Condic
  2002-09-16 18:48 ` Jeffrey Carter
  2002-09-17  9:14 ` David C. Hoos, Sr.
  3 siblings, 0 replies; 7+ messages in thread
From: Marin David Condic @ 2002-09-16 12:08 UTC (permalink / raw)


That depends a lot on how A_Integer is declared. For one thing, when you are
de-referencing the array, you are talking about an object of its component
type, not an array, so the "(others =>...)" aggregate is probably
inappropriate. (A_Integer (2) probably references an object of type
"Integer" - which is not an array and to which you can't assign an
aggregate - but we'd have to see the declaration.) Secondly, *if* the array
is composed of objects of type Integer, then the aggregate references a
constant of type Unversal Real - which is a type mismatch. (2.0 is not the
same as 2 - at least in Ada context).

So you might get:

A_Integer (2) := 2 ;

to work Or possibly you might get:

A_Integer (2..3) := (others => 2);

to work (because now it is an array slice). Post a bit more code if this
doesn't explain it.

MDC

--
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jast.mil/

Send Replies To: m c o n d i c @ a c m . o r g

    "I'd trade it all for just a little more"
        --  Charles Montgomery Burns, [4F10]
======================================================================

prashna <vashwath@rediffmail.com> wrote in message
news:d40d7104.0209160302.3a15485e@posting.google.com...
> Hi all,
> Pls explain what is wrong in this statement?
>
> A_Integer(2) := (others => 2.0);
>
> where A_Integer is an array of integer, whose index is integer ranging
> form 1..10.
>
> I am using Tartan compiler on Aix machine and the error is
> "segmentation fault (core dumped)"
> Thanks in Advance.





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

* Re: Question on arrays
  2002-09-16 11:02 Question on arrays prashna
  2002-09-16 12:03 ` Preben Randhol
  2002-09-16 12:08 ` Marin David Condic
@ 2002-09-16 18:48 ` Jeffrey Carter
  2002-09-17  9:14 ` David C. Hoos, Sr.
  3 siblings, 0 replies; 7+ messages in thread
From: Jeffrey Carter @ 2002-09-16 18:48 UTC (permalink / raw)


prashna wrote:
> A_Integer(2) := (others => 2.0);
> 
> where A_Integer is an array of integer, whose index is integer ranging
> form 1..10.
> 
> I am using Tartan compiler on Aix machine and the error is
> "segmentation fault (core dumped)"

That's not a very useful error message.

If I read your description of A_Integer correctly, it is declared 
something like

A_Integer : array (1 .. 10) of Integer;

or the equivalent with a named array type.

In that case, "A_Integer (2)" is an Integer, while "(others => 2.0)" is 
an aggregate. To simplify, an aggregate can be considered a literal of a 
composite type. Since the left-hand side is a non-composite type 
(Integer) and the right-hand side is a value of some composite type (an 
aggregate), they do not match and the assignment is illegal.

I won't go into the difference between "2.0" and "2". If you don't 
understand that yet, then you need to work through some basic tutorials 
or texts on Ada before trying what you're working on.

-- 
Jeff Carter
"Oh Lord, bless this thy hand grenade, that with it thou
mayst blow thine enemies to tiny bits, in thy mercy."
Monty Python and the Holy Grail




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

* Re: Question on arrays
  2002-09-16 12:03 ` Preben Randhol
@ 2002-09-16 19:15   ` tmoran
  2002-09-17  4:53     ` prashna
  0 siblings, 1 reply; 7+ messages in thread
From: tmoran @ 2002-09-16 19:15 UTC (permalink / raw)


I wonder if there's some problem the OP didn't mention.  A segmentation
fault seems a little surprising as a compiler error message for such a
straightforward pair of errors.  Does the segmentation fault still
occur if you change the 2.0 to 2?  Or if you get rid of the aggregate
or change the array element to a slice?



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

* Re: Question on arrays
  2002-09-16 19:15   ` tmoran
@ 2002-09-17  4:53     ` prashna
  0 siblings, 0 replies; 7+ messages in thread
From: prashna @ 2002-09-17  4:53 UTC (permalink / raw)


tmoran@acm.org wrote in message news:<f5qh9.332184$_91.425787@rwcrnsc51.ops.asp.att.net>...
> Does the segmentation fault still
> occur if you change the 2.0 to 2?  

Yes.

> Or if you get rid of the aggregate
>or change the array element to a slice?

I removed others and the statment looked like this A_Integer(2) := 2;
and did'nt get any error.

>A segmentation
>fault seems a little surprising as a compiler error message for such
a
>straightforward pair of errors.  

Yes, even I am wondering as to why it gave segmentation fault!!!!!!!?



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

* Re: Question on arrays
  2002-09-16 11:02 Question on arrays prashna
                   ` (2 preceding siblings ...)
  2002-09-16 18:48 ` Jeffrey Carter
@ 2002-09-17  9:14 ` David C. Hoos, Sr.
  3 siblings, 0 replies; 7+ messages in thread
From: David C. Hoos, Sr. @ 2002-09-17  9:14 UTC (permalink / raw)


After having read all of the replies to your original post,
it appears that no one has addressed the original problem --
i.e. why a compiler should die with a segmentation fault,
regardless of what kind of illegal code is submitted to it.

It could be that what is actually happening is a stack
overflow in the shell environment in which the compiler
executes.

You did not say which shell you're using on AIX -- e.g.,
Bourne, Korn, tcsh, etc.  I have seen many cases of
perfectly good programs (including compilers) die with
a segmentation fault because the stack size limit was
too small.

----- Original Message ----- 
From: "prashna" <vashwath@rediffmail.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: September 16, 2002 6:02 AM
Subject: Question on arrays


> Hi all,
> Pls explain what is wrong in this statement?
> 
> A_Integer(2) := (others => 2.0);
> 
> where A_Integer is an array of integer, whose index is integer ranging
> form 1..10.
> 
> I am using Tartan compiler on Aix machine and the error is
> "segmentation fault (core dumped)"
> Thanks in Advance.
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
> 
> 





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

end of thread, other threads:[~2002-09-17  9:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-16 11:02 Question on arrays prashna
2002-09-16 12:03 ` Preben Randhol
2002-09-16 19:15   ` tmoran
2002-09-17  4:53     ` prashna
2002-09-16 12:08 ` Marin David Condic
2002-09-16 18:48 ` Jeffrey Carter
2002-09-17  9:14 ` David C. Hoos, Sr.

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