Share good ideas and conversation.   Login, Join Us, or Take a Tour!
comment by bfv
bfv  ·  460 days ago  ·  link  ·    ·  parent  ·  post: Ph.D. students face significant mental health challenges

In this one instance I say it's a feature, not a bug ;)




Devac  ·  460 days ago  ·  link  ·  

Oh, now you're just being reasonable about a language that allows you to commit some proper code-atrocities:

  #include <stdio.h>

#include <stdlib.h>

  int main(void)

{

char * str = (char*)malloc(1);

free((void*)(str[10] = '\0'));

str[1] = 'a';

printf("%s", str);

free((void*)str);

return 0;

}

This compiles and doesn't cause segfault. Believe me, I get what you are saying.

EDIT: Changed the allocated amount of space, not that it mattered to the compiler…