Menu

#43 What about promotion?

open
nobody
None
5
2007-06-29
2007-06-29
Anonymous
No

static unsigned short v = 2;

void f( void )
{
int i;

i = -v;
}

results in

Splint 3.1.1.2 --- 27 May 2007

redef.c: (in function f)
redef.c:7:3: Assignment of unsigned short int to int: i = -v
To ignore signs in type comparisons use +ignoresigns

Finished checking --- 1 code warning

Taken literally, the warning message is wrong, because when evaluating the assignment expression, first, v is promoted to int, then its value is negated, then the assignment is performed between two ints.

I am not sure what position splint should take about promotions performed by the translator when evaluating expressions, but the word "promote" or "promotion" does not even occur in the 3.1.1-1 splint manual.

The warning is justified, but it perhaps should say something about promoting unsigned int to signed int, which has a real tendency of playing tricks on programmers.

br
pkzc at freemail dot hu

Discussion


Log in to post a comment.

MongoDB Logo MongoDB