API : constness ?

Isaac To kkto at csis.hku.hk
Tue Jun 1 08:49:13 CEST 2004


>>>>> "Erik" == Erik Max Francis <max at alcyone.com> writes:

    Erik> To his credit, he was talking about declaring an array of strings
    Erik> as const char *const.  That is, he was indeed making the data he
    Erik> was passing in truly const.  As others have pointed out, though,
    Erik> that doesn't guarantee that that data will be put in read-only
    Erik> memory, only that it makes it possible.

This is not quite right.  A string literal is always put into read-only
memory, no matter whether you specify const or not.  So:

  int main() {
      char *str = "abc";
      str[0] = '\b'; // segmentation fault
  }

On the other hand, as I've stated in another thread, an array of initialized
pointers can never be put into read-only memory in a module, due to other
restrictions.

Regards,
Isaac.



More information about the Python-list mailing list