stricter C++ prototypes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Sometime soon we'll have gcc 4.4 in rawhide as the new system compiler.
 This alone might bring with it changes in the C++ language acceptance
(I don't know details).

What I want to warn people about is another change which will come in
combination with the next glibc.  For a long time some of the function
prototypes for string functions you get when including <cstring> and
<cwchar> (or the underlying C headers) are wrong.  Only for C++, C is
not affected.

   char *strchr (const char *, int)

should be

   char *strchr (char *, int)
and
   const char *strchr (const char *, int)

I.e., the const is preserved correctly.

The result of this that some incorrect programs might not compile
anymore.  For strchr this might look like this:

int foo (const char *s)
{
  char *p = strchr (s, 'f');
  return p == 0 || p[1] == '\0';
}

Previously this worked fine.  strchr returned a value of type char*.
Now, and correctly, it returned a const char*.  But in C++ assigning a
const T* value to a T* variable is an *error* (not a cause for a warning).

I expect the fixes are simple in most cases.  Don't just use casts, use
correct types for the variables etc.  This type safety helps to
eliminate bugs in the code.

- --
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkmCTnsACgkQ2ijCOnn/RHQFYACdHhWrdTZ9pheyuhurPnSW5fn0
cd4AoKkBmdKyVrpLV4NxxFgMk35gxEry
=gGoC
-----END PGP SIGNATURE-----

-- 
fedora-devel-list mailing list
fedora-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/fedora-devel-list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Fedora Announce]     [Fedora Kernel]     [Fedora Testing]     [Fedora Formulas]     [Fedora PHP Devel]     [Kernel Development]     [Fedora Legacy]     [Fedora Maintainers]     [Fedora Desktop]     [PAM]     [Red Hat Development]     [Gimp]     [Yosemite News]
  Powered by Linux