I know that variable which is declared with 'static' modifier in a C++ function is initialized only once and what I want to do is to initialize static dynamically allocated array with appropriate content. Here is my code fragment:
inline char* getNextPass()
{
static int chars_num = chars_data.charset_len, pass_len = chars_data.pass_len ;
static int *cur_pos = new int[pass_len] ; // this is static variable in function, what means it's initialized only once
...
for(int aa = 0; aa < pass_len; aa++) // this is executed every time the function is called. How can I make this code execute only once ?
cur_pos[aa] = 0 ;
...
}
I know of course that I could do something like this:
...
flag = true ;
...
inline char* getNextPass()
{
...
if(flag)
for(int aa = 0; aa < pass_len; aa++)
cur_pos[aa] = 0 ;
flag = false ;
...
}
but it's probably not optimal way of coding and can be done somehow more effectively. Can I use 'static' moddifier some way to make more optimized implementation ?
staticinstance of that class.