C & C++

C & C++

Made by DeepSource

Found shadowing of identifiers from outer scope CXX-W1023

Bug risk
Major

Having identifiers unintentionally shadowed from the outer scope by the inner scope can possibly lead to bugs in code.

Consider using unique identifier names.

Bad practice

int main(int argc, char** argv) {
    for (int i = 0; i < argc - 1; i++) {
        int argc = i + 1;
        // do stuff
        printf("arg %d of %d", i, argc);
    }
}

Recommended

int main(int argc, char** argv) {
    for (int i = 0; i < argc; i++) {
        int argi = i + 1;
        // do stuff
        printf("arg %d of %d", i, argc);
    }
}

References