Splint: local variable used before definition

I know that local variables can have a "random" value if not set, but is it bad to set the first value of a local variable with a pointer? For instance:

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;
}

If setValue sets and never reads the value of the reference variable. Splint warns me that val is "used before the definition", and I'm a little surprised by this warning, since I believe that val should be set before printf is executed, and val is used. Is the bus not advanced enough to recognize the link used to set the initial value?

+4
source share
1 answer

setValue(&val); val - , , .

( ), .

int val = setValue();

?

+6

Source: https://habr.com/ru/post/1690130/


All Articles