rCs said:
How sound is the following advice for a C language coding standard?
"Explicitly cast or convert variables. Do not rely on the implicit
conversions."
I agree with the other posters opposing that as a general rule. Using
casts for assignment to objects with types smaller than the maximum
possible, based on the type of operands and operations within a
statement makes more sense:
char c1, c2;
int i;
long la, lb;
/* assign initial values somehow */
c1 = 'a'; /* can't truncate, no cast */
c2 = c1; /* can't truncate */
c2 = c1 & 0x7f; /* can't truncate */
c2 = (char)(c1 + 5); /* could truncate* */
c2 = (char)i; /* could truncate */
i = (int)(la - lb); /* could truncate */
i = i * 100; /* might overflow, but no cast */
Personally, I probably wouldn't use a cast of c2 = c2 + 5, relying
instead on knowing the range of values to be handled.