Re: When are unnecessary casts useful?
- From: "David T. Ashley" <dta@xxxxxxxx>
- Date: Tue, 9 Jan 2007 09:56:21 -0500
"jacob navia" <jacob@xxxxxxxxxxxxxxxx> wrote in message
news:45a395ad$0$25906$ba4acef3@xxxxxxxxxxxxxxxxx
To avoid the warning you have to explicitely cast the LHS to meet
the RHS, like this:
a = (char)b;
The cast makes your intentions clear.
The same approach exists in Microsoft compilers.
I have gotten used to do this, more or less automatically when I
cast "down", i.e. from a bigger to a smaller type.
This comes down to one of the oldest arguments with programming, especially
with 'C'. You should look at Les Hatton's classic work, "Safer C".
Even in areas of the language that are well-defined (i.e. the compiler won't
make mistakes); statistically, humans make mistakes.
You might find in a lot of corporate coding standards the requirement that
if() conditions, be fully parenthesized, i.e.
if ((!a) || (*a > 10))
An experienced programmer will argue this requirement is rubbish (i.e. any
programmer should know precedence and order of evaluation), whereas
management would argue either that (a)it is an area where people are prone
to make mistakes and/or (b)it becomes relevant when there is a team at a
mixed skill level.
This thread and all its derivatives is older than time. (Or, at least it
dates back to nearly 1972.)
.
- Follow-Ups:
- Re: When are unnecessary casts useful?
- From: ais523
- Re: When are unnecessary casts useful?
- References:
- When are unnecessary casts useful?
- From: jacob navia
- When are unnecessary casts useful?
- Prev by Date: Re: When are unnecessary casts useful?
- Next by Date: Re: Bit fiddling calculating fraction
- Previous by thread: Re: When are unnecessary casts useful?
- Next by thread: Re: When are unnecessary casts useful?
- Index(es):
Relevant Pages
|
Loading