Large Array Initialization to 0
Asked Answered
F

1

6

Is there a way to initialize a two dimensional array without giving all the values one by one.

I have signal declaration like :

  type t_id_data is array (integer range <> ) of integer; 
  type t_image_data is array (integer range <>) of t_id_data;
  signal s_image_data : t_image_data ( 0 to 30) (0 to 720);

I want to initialize this to 0. It is an integer array.

Thanks,

Filler answered 1/6, 2017 at 13:2 Comment(0)
G
11

Yes. You use an aggregate. Let's reduce the sizes of the arrays for clarity:

type t_id_data is array (integer range <> ) of integer; 
type t_image_data is array (integer range <>) of t_id_data;

-- this sets element 0 to {0, 10, 100} and elements 1,2 to {0, 11, 0} 
-- using NAMED ASSOCIATION
signal s_image_data : t_image_data ( 0 to 2) (0 to 2) 
  := (0 => (0 => 0, 1 => 10, 2 => 100), 
      others => (1 => 11, others => 0));  

-- this sets all the elements to 0
signal another_signal : t_image_data ( 0 to 2) (0 to 2)
  := (others => (others => 0));  

-- this sets element 0 to {0, 10, 100} and elements 1,2 to {0, 11, 0} 
-- using POSITIONAL ASSOCIATION
signal yet_another : t_image_data ( 0 to 2) (0 to 2) 
  := ((0, 10, 100), others => (0, 11, 0));  
Garnishee answered 1/6, 2017 at 13:28 Comment(1)
Thank you, this was helpful.Filler

© 2022 - 2024 — McMap. All rights reserved.