Changes between Version 9 and Version 10 of const


Ignore:
Timestamp:
Sep 15, 2010, 7:44:43 PM (11 years ago)
Author:
andersk@mit.edu
Comment:

s/the the/the/

Legend:

Unmodified
Added
Removed
Modified
  • const

    v9 v10  
    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 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].
     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 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 ==