Re: Why compiler not generating any warning ?
- From: junky_fellow@xxxxxxxxxxx
- Date: 4 Jun 2005 01:22:25 -0700
I thank you all for your answers. From the various replies in this
thread what I concluded is that:
1) One should aviod using casts while writing a program that is
supposed to be portable. casts are sign of bad design.
2) Sometimes while writing a piece of code that has to
directly access h/w (device drivers, embedded s/w) casts may be
the only option. In such cases, one must be aware of the consequences
of typecasting. Also, in such cases code review is the best
tool to find out such bugs. Compiler may not be issuing the
warning for all such *incompatible* casts.
Still I have one question. I might sound irritating but its better to
ask. Please bear with me. As most of you said that the compiler
didn't generate any warning because it was explicitly told to do
so. But there are other cases as well where explicit cast is done,
still the complier gives the warning.
eg.
int main(void) {
char * c_ptr;
int * i_ptr;
(int *)i_ptr = (char *) c_ptr; /* warning for this line */
return(0);
}
compiling this code always generates warning.
.
- Follow-Ups:
- Re: Why compiler not generating any warning ?
- From: Alan J. McFarlane
- Re: Why compiler not generating any warning ?
- From: Jens . Toerring
- Re: Why compiler not generating any warning ?
- From: Keith Thompson
- Re: Why compiler not generating any warning ?
- References:
- Why compiler not generating any warning ?
- From: junky_fellow
- Re: Why compiler not generating any warning ?
- From: CBFalconer
- Re: Why compiler not generating any warning ?
- From: Jens . Toerring
- Why compiler not generating any warning ?
- Prev by Date: Re: Bit twiddling
- Next by Date: Re: Returning pointer to array problem II
- Previous by thread: Re: Why compiler not generating any warning ?
- Next by thread: Re: Why compiler not generating any warning ?
- Index(es):
Relevant Pages
|