Having multiple initializer functions in a constructor
Lint checks, if all of the members are initialized in the constructor. Optionally this check could be redirected to an initializer-function introduced with the -sem Command. But then the initialization has to be done completely in the initializer-function.
In our embedded software it is quite common to have more than one function doing the initialization task, e.g.:
class A
{
public:
A()
{
membera = 0;
initFunction1();
initFunction2();
}
private:
void initFunction1()
{
memberb = 0;
}
void initFunction2()
{
member_c = 0;
}
int member_a;
int member_b;
int member_c;
};
It would be very helpful, that lint supports this way of doing initializations.
In the upcoming PC-lint Plus, full or partial initializations that takes place in functions called by a constructor are automatically recognized without the need for an initializer semantic. In the example provided, no message would be issued. The initializer semantic can still be used if the definition of an initializing member function is not available but otherwise isn’t necessary.
-
Kurt commented
FYI, this issue is also described on the forum: http://www.gimpel.com/Discussion.cfm?ThreadID=3865&SessionID=4739975
It would be nice if lint could look at the sum total of initializations provided by the constructor and designated initialization functions.
-
Catoblepa commented
We have exactly the same problem in our project: initializations are organized in several methods, since parts of the initializtions are also needed later after construction.
In the end we found no better solution than disabling the warning 1565 at all for the affected classes - too bad.