David Schwartz said:
On Apr 6, 2:33 am, (e-mail address removed) wrote: [...]
I see a lot of unnecessary casts
Sure, but you still know when you see the cast that:
1) The programmer is vouching for the safety of the cast, and
2) The programmer intended the conversion.
[...]
Certainly (well, almost certainly) the presence of a cast implies that
the programmer intended a conversion. But it does *not* imply, any
more than the absence of a cast, that the programmer is vouching for
the safety of the conversion. Nothing short of a comment saying "I
vouch for the safety of this conversion" would convey that information
to me.
Since some compilers, in the case being discussed, will issue a
warning if there is no cast, but will not issue a warning if there is
a cast, it's entirely possible that the programmer added the cast
merely to silence the warning. This does not imply that the
programmer knew what he was doing.
Another possibility is that the programmer used a cast because he
wasn't aware that the conversion would be done implicitly without it.
If I'm going to assume perfect competence on the part of the
programmer, then an assignment without the cast tells me just as much
as the assignment with the cast, since the programmer must be aware
that there's an implicit conversion, and wouldn't have written the
assignment without knowing that it's safe. Without that assumption,
the presence of an *unnecessary* cast would, in my mind, cast (*sigh*)
doubt on the programmer's competence.
If you work in an environment where a cast always means "I guarantee
the safety of this conversion", then the assumptions you make are
reasonable in that environment. But that's not what a cast means,
either in the language as defined by the C standard or in any
programming environment I've seen.
Don't assume that your experience is universal.