Fwd: stricter C++ prototypes

Debarshi Ray <[email protected]>
Newsgroups gmane.user-groups.linux.kolkata
Message-ID <[email protected]>
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 <[email protected]>
Date: 2009/1/30
Subject: stricter C++ prototypes
To: Development discussions related to Fedora Core
<[email protected]>


-----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
[email protected]
https://www.redhat.com/mailman/listinfo/fedora-devel-list
_______________________________________________
Ilug-cal-discuss mailing list
[email protected]
http://list.ilug-cal.org/mailman/listinfo/ilug-cal-discuss
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.