glug-nith-discuss
[Top][All Lists]
Advanced

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

[Glug-nith-discuss] Fwd: stricter C++ prototypes


From: Debarshi Ray
Subject: [Glug-nith-discuss] Fwd: stricter C++ prototypes
Date: Fri, 30 Jan 2009 10:39:51 +0530

Although coming from a Fedora mailing list, I think this would be
relevant for any C++ developer using the GNU tool chain.

Cheers,
Debarshi


---------- Forwarded message ----------
From: Ulrich Drepper <address@hidden>
Date: 2009/1/30
Subject: stricter C++ prototypes
To: Development discussions related to Fedora Core
<address@hidden>


-----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
address@hidden
https://www.redhat.com/mailman/listinfo/fedora-devel-list




reply via email to

[Prev in Thread] Current Thread [Next in Thread]