TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Sender:
"Team Ada: Ada Advocacy Issues (83 & 95)" <[log in to unmask]>
Subject:
From:
Todd Coniam <[log in to unmask]>
Date:
Tue, 6 May 1997 19:56:00 -0400
X-To:
Reply-To:
Parts/Attachments:
text/plain (38 lines)
In a message dated 97-05-06 14:32:27 EDT, [log in to unmask] (Alexandre
Crozat) writes:

<< Is it possible to initialize a multi-dimensionnal array during its
definition?
 For single-dimensional arrays, the answer is yes:
    Init : array (0 .. 3) of Integer := (0 => 1, others => 0)
 but what about a 2d array which I would like to fill with zeros?
  >>
Yes Alexandre, it's quite simple:

  Init : array (0..3, 0..3) of integer := (others => (others => 0));

or the long, long way:

  Init : array (0..3, 0..3) of integer := (
       0 => (0 => 0, 1 => 0, 2 => 0, 3 => 0),
       1 => (0 => 0, 1 => 0, 2 => 0, 3 => 0),
       2 => (0 => 0, 1 => 0, 2 => 0, 3 => 0),
       3 => (0 => 0, 1 => 0, 2 => 0, 3 => 0)
       );

or even:

  Init : array (0..3, 0..3) of integer :=
((0,0,0,0),(0,0,0,0),(0,0,0,0),(0,0,0,0));

(I appologize if this isn't a good coding style, It gets the point across
though)

OBTW, I would avoid anonymous types for the array indicies, it can lead to
problems!

Have Fun!

Todd Coniam
t c o n i a m  at  a o l  dot  c o m

ATOM RSS1 RSS2