Re: Program crashes when running it outside dev environment



Richard Heathfield wrote:
David Tiktin said:

On 08 Jun 2007, Richard Heathfield <rjh@xxxxxxxxxxxxxxx> wrote:

So my suggestions would be:

1) crank up your warning level to the max
2) turn off any extensions you can live without
3) fix every single diagnostic message, and *never* with a cast

I'm with you right up to the last clause. Are you saying you never
actually *need* a cast?

No, there are (rare) occasions when you do need a cast. But I don't know
of any occasion where you *need* a cast AND omitting it violates a
constraint or constitutes a syntax error. So adding a cast is not the
right way to fix a diagnostic message. If the choice is between adding
bad code and putting up with a bad warning, I'll live with the bad
warning.

I can't think of a concrete example of a cast which causes a constraint
violation or syntax error when left out either, but diagnostics are
permitted for other code as well.

#include <stdio.h>
int main(void) {
int *p = NULL;
printf("%p\n", p);
}

example.c:4: warning: format ‘%p’ expects type ‘void *’, but argument 2 has
type ‘int *’

And a cast is the right way to fix the bug.
.



Relevant Pages