Q:

Splint: local variable used before definition

I know local variables can have "random" value when not set, but is it bad to set the first value of a local variable with a pointer? For example:
void setValue(int* p_val)
{
    *p_val = …; /* Assignment does not use *p_val */
}

int main(void)
{
    int val;
    setValue(&val);
    printf("%d", val);
    return 0;
}

Where setValue only sets and never reads the value of the referenced variable. Splint warns me that val is "used before definition" and I'm a bit suprised about that warning since I believe the value of val to be set before printf is executed and val used. Is splint not advanced enough to recognize the reference being used to set the initial value?

A:

If setValue(&val); does assign val to something via a pointer deference, then the behaviour of your code is defined, and the analysis tool is incorrect.
But if you can avoid having variables in uninitialised states (without superfluous assignments), then that would be preferable. Would it be possible to refactor to
int val = setValue();

say?

