On 2/19/2018 4:14 AM, Chris Angelico wrote:
On Mon, Feb 19, 2018 at 7:40 PM, Alain Ketterlin
<al...@universite-de-strasbourg.fr.invalid> wrote:
Tim Delaney <timothy.c.dela...@gmail.com> writes:
C is statically and weakly typed. Variables know their types at compile
time (static typing). It is a feature of the language that you can cast any
pointer to any chunk of memory to be a pointer to any other type (normally
via void *). This is not coercion - it takes the bit pattern of memory of
one type and interprets it as the bit pattern for another type, and is weak
typing.

No. C has much stronger rules, not on casting, but on accessing the
pointees, which basically invalidates your argument. Refer to the C
standard for details.

Really? What rules?

$ cat demo.c; gcc -Wall demo.c; ./a.out
#include <stdio.h>

int main() {
     float f = 3.14159;
     int *i = (int *)&f;
     printf("As an integer, %f is %d\n", f, *i);
     return 0;
}

As an integer, 3.141590 is 1078530000
$

Looks to me like C is perfectly happy to interpret a float as an int.
What rules are you seeing violated here?

The last time I tried, C was also willing to ints and arrays thereof as an array of chars. (I vaguely remember Fortran doing something like this also. One Fortran int = four chars.) The C memory model is a linear sequence of bytes, each consisting of at least 8 bits. One means for malware attacks it is to disguise and insert binary code bytes as character bytes and then trick the CPU into executing the 'characters'.

--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to