All pastes #485641 Raw Edit

Tha-Doctor

public cpp v1 · immutable
·published 2007-05-13 03:45 UTC
rendered paste body
   const char *x;   char const *a = x;   char *b;   char *c = "ABCDEF";   b = (char*)malloc(sizeof(char)*120);   memcpy(b, "Anything", 9);   // Illegal   memcpy(c, b, 5);  // c points to a "constant" memory area      // Legal   x = b;   // x (the pointer) can be modified   // Illegal   memcpy(x, "1234", 5);  // Although the memory is not constant, x is a pointer to constant memory, so this should not be allowed   // Illegal   a = x;    // a cannot point to any other place (a cannot be modified)      // Legal   free(b);   b = strdup(c);   // Now you can use a COPY of the data that is constant in a non-constant memory area// and so on...