Here say NU_OF_LINES = 4,
string ID[NU_OF_LINES] = {"0,1,2,3"}; Here the right hand side is hard coded. I want to automate this something like : string ID[
NU_OF_LINES] = {“0,//generate entries depending on `NU_OF_LINES-1”// }
What is the right way to achieve this.
In reply to ibrahim_hussain:
You can use following syntax , but it assigns default value to all entries.
// assign 0 to all entries
string name_[`NO_OF_LINE] = '{`NO_OF_LINE{0}};
In reply to ibrahim_hussain:
You can use a function to initialize a variable.
typedef string stringUA_t[`NO_OF_LINES]; //typedef needed for function retuning unpacked array
function stringUA_t IDlist;
foreach(IDlist[ii]) IDlist[ii].itoa(ii);
endfunction
string ID[`NO_OF_LINES] = ID_list;
If you are going to have a lot of different arrays to initialize, you can use a dynamic array instead.
typedef string stringDA_t[]; //typedef needed for function retuning unpacked array
function stringDA_t IDlist(int number);
IDList = new[number];
foreach(IDlist[ii]) IDlist[ii].itoa(ii);
endfunction
string ID[`NO_OF_LINES] = ID_list(`NO_OF_LINES);