Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Can your C compiler do this:

Name: Anonymous 2010-05-15 15:06


int main()
{
  int *p;
  p  = 0;
  *p = 0;
  return 0;
}


?

Name: >>38 2010-05-16 5:44

Altough, I guess if you reserve the memory area represented by NULL (be it a valid address containing real data, or not), then nothing else could be using it, so as long as the user checks if memory allocation functions return NULL, then the allocation has failed. One could use page protection to make reads/writes to it fail as well, but it's not possible on all archs. This way, even if there's some real data at *NULL, it would be the user's fault for dereferencing it, as by convention NULL shouldn't be a pointer the user should access normally (the convention would only be broken during the initial setup of the pointer, which could be done by the OS or the C runtime). Some errors might be unnoticed, but it might fit the needed definition.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List