Computer Scientist

Saturday, 23 March 2013

C/C++ Programming Tips

Here, some useful tips or unknowns of C/C++ programming are listed for further reference:

1. Stand alone curly brackets in code.
Sometimes a pair of curly brackets can be found in a C/C++ code file. It seems to be useless:

Configurator::only ().dump();

{
    strbuf x = strbuf ("starting: ");
    for (int i = 0; i < argc; i++) {
        x << argv[i] << " ";
    }
    x << "\n";
    info << x;
}

Here, the curly brackets is not necessarily to exist. However, they have their meanings from two different point of views: Scope perspective and Legacy perspective.
In scope perspective, the codes in the pair of curly brackets is in a new sub scope.
In legacy perspective, the legacy C standard needs variable declarations to be in the very front of the code. The curly brackets are able to make a new "beginning".
I am working on a C++ project. So the original coder considered in a scope perspective.

No comments:

Post a Comment