Re: setlocale: Silence a -Wdiscarded-qualifiers warning on Windows.

Alejandro Colomar <[email protected]>
Newsgroups gmane.comp.lib.gnulib.bugs
Message-ID <aibvzA0nL9d0SqrE@devuan>
Hi Bruno,

On 2026-06-07T21:35:07+0200, Bruno Haible wrote:
> Collin Funk wrote:
> > > But we can add the intended return type in Gnulib. Done as follows. This
> > > patch removes two casts, instead of adding a cast.
> > 
> > I considered suggesting this as well for the same reason you mention,
> > i.e., the standard saying the returned string cannot be modified. But I
> > mistakenly assumed you would not want to diverge from the standardized
> > prototype.
> 
> We had some (conditional) change of return type from 'char *' to 'const char *',
> or from 'void *' to 'const void *', in functions like strchr and memchr,
> and although it was a bit of a hassle for the people who maintain very old
> packages, it was a worthwhile modernization.
> 
> In POSIX, the following functions are marked with
>   "The application shall not modify the string returned."
> and could therefore be modernized:
>   ctermid
>   dlerror
>   getgrent
>   getgrgid, getgrnam
>   gethostent
>   getlogin
>   getnetent, getnetbyaddr, getnetbyname
>   getprotoent, getprotobyname, getprotobynumber
>   getpwent, getpwnam, getpwuid
>   getservent, getservbyname, getservbyport
>   localeconv
>   nl_langinfo, nl_langinfo_l
>   ptsname
>   setlocale
>   strerror, strerror_l
>   strsignal
>   ttyname
>   *gettext, *gettext_l

getenv(3) should also be included in that list, I believe.  It is also
in ISO C, so you may want to change it already, in order to provide
prior art for WG14.


Cheers,
Alex

> 
> > I vaguely remember
> > POSIX being willing to change the return type of gettext to be "const
> > char *" for similar reasons
> 
> That would be useful too, yes.
> 
> > Perhaps it is worth bringing this up with the ISO C people.
> 
> Yes, that would be useful, both for setlocale() and for localeconv().
> 
> Bruno
> 
> 
> 

-- 
<https://www.alejandro-colomar.es>
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmom7/kACgkQ64mZXMKQ
wqk6XQ//Z9QXxkeJthiOaZZFb0zSZub4cHnYJJjehs6Qogx3Lmgq1XSQ7H8CTO/Q
dVs4AkVf1qfy6nHYAnfxHXC7Kb2NDz3s8i1L8vK/t/mjmUtxCm9wwCuESqGSMXv7
99FUQcUTDKQVlocWzPbh7R522ytVOYTrMG54q/PruYdB4q0kEV5F7nRVOjEJUZuI
eF6GI+9DYujRYdG7gobFjlkTSq9QLmJ4mKXALfwZEJFdWeHd+Lzc2PRKiykD/O5j
UYPVFOE+lxU9JhHjrFUkhwdmVTmGOd9AusIGeRruvQEqbnJUneo3ipvpsbucfk/p
zz+xysw0elHay40URZVKdtdHASA3RI7nQk4f2vAl4F5Lbrg6NS+VihqDFJ8mEeEe
Pupv0pdVU55QmToLaiMe1X81agK/Uwl1oZB0H4n7qLzSMtQ/IBRe1US7qQ/Unnmi
1tT8j6zp3xNc/serjtHo/yvpCd6+JyYg49MCSO4PRhW9d27CoV2TLQc+F+5LRb4k
Vi35i7wPkI2FaUswOU5jFPvf0ZgTUW26H3v4LgVye5xzRQ3n16wtEhhxpTGJT/uE
kayDyfHlkQLCxH1YQY9PKwDBy3K00+XaSn1zAiLPd4qpz661lNhmpU2hI88hDwOQ
RyMYodLTDfHT0qpIeiUtPB5sdxGSl9b5ocqqgKdVYxr6yzuLFaI=
=9wnW
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.