View Single Post
Old Mar 2nd, 2008, 4:04 PM   #3
Seif
Hobbyist Programmer
 
Seif's Avatar
 
Join Date: Jan 2006
Location: UK
Posts: 215
Rep Power: 3 Seif is on a distinguished road
Re: I need help in writting pseudocode

Quote:
Originally Posted by Sane View Post
  1. When you are declaring an array, if you need to make the size dynamic (dynamic size is when the program does not yet know the size until after it has been compiled), then you need to use some other techniques such as "malloc" or "new".
Don't mean to be pedantic, but thats not 100% true. The C99 standard allows variable length arrays. That is, an array of automatic storage duration whose length is determined at run time.

For example the following code is valid:

int foo(int len)
{
    int vla[len];
    for (int i = 0; i < vla[len]; i++)
        vla[i] = i;
    for (int i = 0; i < vla[len]; i++)
        printf("%i\n", vla[i] = i);
}

Of course VLA operands will cause problems when compiled with C++. As you mentioned you could use C or C++, you may want to consider moving to a compiler that will support C99.

of course you must also make sure that the expression you are using to specify the size of the array is defined first .
Seif is offline   Reply With Quote