J
joshc
I searched through the newsgroup for this and found the answer but
wanted to make sure because of something that came up.
I want the absolute value of a 'short int' so to avoid the dangers of
overflow I am doing the follow:
short int x = -4; /* want abs(x) */
unsigned short int abs_val;
....
/* already performed check to make sure x is negative */
abs_val = -(unsigned short int)x;
I take it that the above is how I should safely get the absolute value
of a negative number. I want to confirm this because my Lint package
says that there is a:
"Loss of sign(assignment)(int to unsigned short)."
Thanks!
wanted to make sure because of something that came up.
I want the absolute value of a 'short int' so to avoid the dangers of
overflow I am doing the follow:
short int x = -4; /* want abs(x) */
unsigned short int abs_val;
....
/* already performed check to make sure x is negative */
abs_val = -(unsigned short int)x;
I take it that the above is how I should safely get the absolute value
of a negative number. I want to confirm this because my Lint package
says that there is a:
"Loss of sign(assignment)(int to unsigned short)."
Thanks!