PEP 526 - var annotations and the spirit of python

Peter J. Holzer hjp-python at
Tue Jul 17 02:44:53 EDT 2018

On 2018-07-15 08:37:05 +0200, Christian Gollwitzer wrote:
> Am 05.07.18 um 12:04 schrieb Steven D'Aprano:
> > On Thu, 05 Jul 2018 09:17:20 +0200, Christian Gollwitzer wrote:
> > But... it compiles? Seriously?
> > Sometimes I wonder how C programmers manage to write a bug-free "Hello
> > World" program. No wonder it is described as a type-unsafe language or a
> > weakly-typed language.
> Even this compiles:
> #include <stdio.h>
> int main() {
> 	int x=1;
> 	x="This is serious";
> 	printf("%d\n", x);
> 	return 0;
> }
> Apfelkiste:Tests chris$ gcc intx.c && ./a.out
> intx.c:4:3: warning: incompatible pointer to integer conversion assigning to
>       'int' from 'char [16]' [-Wint-conversion]
>         x="This is serious";
>          ^~~~~~~~~~~~~~~~~~
> 1 warning generated.
> 15294370
> Assignment in C to an integer will only fail when the source is a struct.
> Everything else can be "converted" to an integer by the compiler.

"It compiles" is meaningless when you are talking about the language C
(and not about a particular compiler). The C standard doesn't say that
compilation has to terminate in case of an error. It just requires that
a "conforming implementation shall produce at least one diagnostic
message ... contains a violation of any syntax rule or constraint, even
if the behavior is also explicitly specified as undefined or
implementation-defined." (§ Assigning a pointer to an integer
is a constraint violation (§, and the compiler produces a
diagnostic message, so GCC is conforming here. A compiler which accepted
a sonnet by Shakespeare, printed the message "This source code may not
be valid C" and produced an executable which printed "Francis Bacon" in
an infinite loop would also be conforming.

> > At least it shows a warning. But hell, who pays attention to C compiler
> > warnings? There's *so many of them*.
> In programs that are maintained, the warnings are typically taken seriously.
> Some warnings can be annoying, e.g. warnings from generated code about
> unused variables and such, but if you see a flood of warnings in regular
> code, that is a sign that the code has bad quality or wasn't ever tested on
> the platform you try it to compile.

Right. Also, modern compilers let you turn on and off warning
messages individually. So you can turn off those messages you think are
useless and distracting (and maybe turn on a few additional ones).

I remember a time when many compilers had "warning levels". That was
really annoying, because level n always was missing a few warnings I
found very useful while level n + 1 was burying me in a deluge of
useless warnings.


   _  | Peter J. Holzer    | we build much bigger, better disasters now
|_|_) |                    | because we have much more sophisticated
| |   | hjp at         | management tools.
__/   | | -- Ross Anderson <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <>

More information about the Python-list mailing list