On 2014-05-07 02:59, Cristian Rodríguez wrote:
Ok, let me throw in another example ..
#include <stdio.h> char *strcpy(char *dest, const char *src);
int main(void) { char c[3]; strcpy(c, "fuuuuuuuuuuuuuuuuuuuuuuuuuckme"); printf("%s", c); return 0; }
This is valid but obviously buggy on purpose..
with <string.h> included I get the obvious warning..
In function ‘strcpy’, inlined from ‘main’ at c.c:10:5: /usr/include/bits/string3.h:104:3: warning: call to __builtin___memcpy_chk will always overflow destination buffer return __builtin___strcpy_chk (__dest, __src, __bos (__dest));
No <string.h> and the compiler is silent though the program still crashes. this is more in line with the actual concern I have.
Interesting. Yes, C is rather (c)rude, it allows you to silently shoot your own foot. The idea is that the programmer is master of the universe and knows what he is doing best, not silly dumb machines. That's why I do not like C. Like assembler on steroids. Even though gcc produces a ton of warnings about things that older compilers said nothing about... IMHO, (about) only the kernel should me made in C. Just as an example, if you do the above example in Pascal, it will always use the local function, the one defined in the same file. To call the system library function of the same name, you would have to explicitly call something like system.strcpy(), so no confusion would be possible, and variable checking would work correctly. Not that I say that you should program in Pascal... it is just an example :-) -- Cheers / Saludos, Carlos E. R. (from 13.1 x86_64 "Bottle" at Telcontar)