@mhoye morbidly wondering what a.out does if you run it
5 comments
@aburka ...Running it, printf will attempt to find a format string at location 72 of the memory. And crash. There are helpers in GCC for printf, but currently they only check if *the static string* is a proper format and match the argument. They currently cannot check that the wrong type (a character instead of a string) was provided. @dryak that would require an intimate knowledge of the C language and its typing system (not trivial depending on one's background). And a complete overhaul of how C is parsed in order to carry over the necessary extra information about type to detect this. BUT!... @dryak @aburka Programmers don't like to specify conversions manually, so that's what you get, although C makes it extra spicy by quietly ignoring loss of precision or sign (and compilers don't catch all such errors, it seems). |
@aburka it will segfault and crash.
The key is type errors: in C kanguage "a" is a string, but 'a' has a completely different meaning: it's a character. Basically a number in the ASCII table (I am over simplyfing).
So when GCC sees 'Hello world', it interprets it as 'H' (and complains about the excedent letters - they are not proper UTF-8 multibyte) and interprets it as 72. Then C will automatically convert the number 72 into a pointer (hence the other warning).
...