Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Newsgroups | comp.std.c |
| Subject | Re: Return pointers-to-const where data shall not be modified |
| Date | 2020-05-06 13:18 -0700 |
| Organization | None to speak of |
| Message-ID | <87tv0szuj7.fsf@nosuchdomain.example.com> (permalink) |
| References | <r8urv8$82c$1@solani.org> |
Philipp Klaus Krause <pkk@spth.de> writes:
> There are 4 functions (getenv, localeconv, setlocale, strerror) in the
> standard library that return a pointer and state that the return value
> points to something that "shall not be modified by the program". I
> suggest to make these functions return pointers-to-const, e.g.
>
> change
>
> char *strerror(int errnum);
>
> to
>
> const char *strerror(int errnum);
>
> A draft proposal is at
> http://www.colecovision.eu/stuff/proposal-const-shall-not-be-modified-stdlib.html
The formatting of the last paragraph on that web page could be improved.
> Do you see any problem with this change?
It would likely break existing code, for the same reason that making
string literals const would break existing code.
Any program that has something like:
char *username = getenv("USER");
would have to be modified. That would include any pre-ANSI code that
calls getenv.
(C++ has made some tweaks to some C standard library functions, and it
*could* have modified getenv in this way, but it hasn't.)
> I was wondering if it make sense to also change the char * members of
> struct lconf to const char *, but I fear that change might break more stuff.
I think you mean lconv, and that would likely present the same problem.
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */
Back to comp.std.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Return pointers-to-const where data shall not be modified Philipp Klaus Krause <pkk@spth.de> - 2020-05-06 19:25 +0200
Re: Return pointers-to-const where data shall not be modified Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-05-06 13:18 -0700
Re: Return pointers-to-const where data shall not be modified Chris Peterson <cpeterson@mozilla.com> - 2020-08-19 10:44 -0700
Re: Return pointers-to-const where data shall not be modified Philipp Klaus Krause <pkk@spth.de> - 2020-08-28 11:40 +0200
Re: Return pointers-to-const where data shall not be modified James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-08-28 08:42 -0400
csiph-web