Changes between Version 8 and Version 9 of const


Ignore:
Timestamp:
Jun 13, 2010, 4:31:39 AM (14 years ago)
Author:
andersk@mit.edu
Comment:

Slight wording cleanup.

Legend:

Unmodified
Added
Removed
Modified
  • const

    v8 v9  
    4141If you compile with `gcc -Wwrite-strings`, literal strings will be typed `const char[]` like they should be, to prevent you from making the mistake of storing one in a `char *`.
    4242
    43 String functions in the standard C library accept `const char *` and return `char *`, again for compatibility; this does not cause problems because of the implicit conversion from `char *` to `const char *`.  (Note that abuses such as `const char *p; char *q = strstr(p, "");` are still unsafe even though they fail to be disallowed by the signature of `strstr`.)  However, a few functions like `execv` that deal with ''pointers'' to strings (or arrays of strings) were forced to choose one or the other, and they take `char **` or `char *const *` rather than `const char *const *`.  A cast is required to use these functions with `const char *` strings.  glibc’s `getopt` is a [http://www.kernel.org/doc/man-pages/online/pages/man3/getopt.3.html#CONFORMING_TO particularly special case].
     43String functions in the standard C library accept `const char *` and return `char *`, again for compatibility; this does not cause problems because of the implicit conversion from `char *` to `const char *`.  (Note that abuses such as `const char *p; char *q = strstr(p, "");` are still unsafe even though the the signature of `strstr` fails to disallow them.)  However, a few functions like `execv` that deal with ''pointers'' to strings (or arrays of strings) were forced to choose one or the other, and they take `char **` or `char *const *` rather than `const char *const *`.  A cast is required to use these functions with `const char *` strings.  glibc’s `getopt` is a [http://www.kernel.org/doc/man-pages/online/pages/man3/getopt.3.html#CONFORMING_TO particularly special case].
    4444
    4545== Using `const` effectively ==