Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Increasing the Size of a Dynamic Array

Part of CommonErrorsCategory

Description

You can't use "r.length++;" or "r.length += 5" to increase the size of a dynamic array. Also, there is still overhead when resizing an array, guessing a needed size would be better.

Example

int main()
{
    char[] r;
    int c;


    if(r.length < c) 
    r.length = r.length + 1;

    /* "r.length++;" isn't allowed. */

    return 0;
}