[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [csmith-dev] csmith-dev Digest, Vol 44, Issue 2



The reason I declared the iterator or control variable outside of the for-statement is because MSVC complained (at least for MSVC 2008) if I have two for-loops stacked together using the same CV, like:

if (int i = 0; ...) {
// loop 1
}

if (int i = 0; ...) {
// loop 2
}

The compiler would complain "i" was declared multiple times. Very annoying.

As I just tested, VS 2015 has no issue with the above code any more. So yes we couldn't rewrite some of the code as compilers getting smarter. But changing the code for the sake of readability is not the most urgent thing. We could make the code base more readable by other means, such as add/correcting comments.

-Xuejun

On Mon, Apr 4, 2016 at 6:00 AM, Gerlach, Jens <jens.gerlach@fokus.fraunhofer.de> wrote:
Hello,

I had a look at the csmit code base some time ago.
In my humble opinion, there is some potential for using C++11 features to simplify (modernize) the code base, e.g,
in src/AbsExtension.cpp there is the following simple function.

void
AbsExtension::GenerateFirstParameterList(Function &curFunc, std::vector<ExtensionValue *> &values)
{
        vector<ExtensionValue *>::iterator i;
        for (i = values.begin(); i != values.end(); ++i) {
                assert(*i);
                CVQualifiers qfer = (*i)->get_qfer();
                Variable * v = VariableSelector::GenerateParameterVariable((*i)->get_type(), &qfer);
                assert(v);
                curFunc.param.push_back(v);
        }
}

One (!) simple use of C++11 would be to declare the iterator variable ‘i’ in the loop (in fact, that is already standard in C++03)
and use ‘auto’ to let the compiler figure out its exact type.
The result would be as follows.

void
AbsExtension::GenerateFirstParameterList(Function &curFunc, std::vector<ExtensionValue *> &values)
{
        for (auto i = values.begin(); i != values.end(); ++i) {
                assert(*i);
                CVQualifiers qfer = (*i)->get_qfer();
                Variable * v = VariableSelector::GenerateParameterVariable((*i)->get_type(), &qfer);
                assert(v);
                curFunc.param.push_back(v);
        }
}

Not a big deal, but there are many place likes this in Csmith.

Regards

Jens