Re: Why compiler not generating any warning ?



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.

.



Relevant Pages

  • Re: Why compiler not generating any warning ?
    ... casts are sign of bad design. ... > warning for all such *incompatible* casts. ... As most of you said that the compiler ... But the most important point is that the assignment is illegal (though ...
    (comp.lang.c)
  • Re: somebody dropped a (warning) bomb
    ... I won't get the warning anymore. ... I personally much prefer a compiler that doesn't warn a lot, ... initialization above as they have somewhat similar drawback. ... I just happen to believe that casts tend to be a lot more dangerous ...
    (Linux-Kernel)
  • Re: why still use C?
    ... >> a compiler warning) you most probably try to do something dangerous. ... >#1 reason to use casts), so you really have to understand what you're doing. ... >> error of not providing a proper prototype for malloc. ...
    (comp.lang.c)
  • Re: why still use C?
    ... but I fail to see the rationale for that. ... > a compiler warning) you most probably try to do something dangerous. ... I think that is a mistake, and I am not going to drop casts that are not ...
    (comp.lang.c)
  • Re: Why compiler not generating any warning ?
    ... One should aviod using casts while writing a program that is ... warning for all such *incompatible* casts. ... As most of you said that the compiler ...
    (comp.lang.c)