What's the best way to minimize the need of run time checks?

Chris Angelico rosuav at gmail.com
Mon Aug 29 08:31:39 EDT 2016


On Mon, Aug 29, 2016 at 10:13 PM, BartC <bc at freeuk.com> wrote:
> In C, you can write this:
>
>  int x;
>
>  x = 5;
>  x = "hello";
>
> With certain compilers (eg. gcc) you only get a warning. (And since I don't
> show warnings to avoid inundation, that seems to compile fine for me!)

That's because strings, in C, are really pointers-to-char, and for
hysterical raisins, pointers can be assigned to integers with just a
warning. (Good code should have an explicit cast here.)

You probably should have warnings enabled. There are a lot of faults
that newer languages flag as errors, but due to backward compat
restraints, C has to accept - but smart compilers will flag them as
warnings. Getting inundated with warnings would be a major code smell.

ChrisA



More information about the Python-list mailing list