This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Ansi violation ?


Version:
gcc 2.95.2 on FreeBSD 4.1

For 2.7.2.3 it works ok.

commandline:
gcc -c -o const.o -Wcast-qual -ansi const.c

Produces:
const.c:16: warning: cast discards qualifiers from pointer target type

Quoting http://www.eskimo.com/~scs/C-faq/q11.10.html:

---
You can use a pointer-to-T (for any type T) where a pointer-to-const-T is
expected. However, the rule (an explicit exception) which permits slight
mismatches in qualified pointer types is not applied recursively, but only at
the top level.
---

I know I shouldn't be doing this anyway, but sometimes include files
do not yet know of 'const' and you have to do it.

const.c attached.

Marc
char	*
func(void)
{
	char		*foo;
	const char	*cfoo = "bar";

	/*  From http://www.eskimo.com/~scs/C-faq/q11.10.html:
	 *
	 *  References: ANSI Sec. 3.1.2.6, Sec. 3.3.16.1, Sec. 3.5.3 
	 *  ISO Sec. 6.1.2.6, Sec. 6.3.16.1, Sec. 6.5.3 
	 *  H&S Sec. 7.9.1 pp. 221-2
	 *
	 *  Use -Wcast-qual with gcc.
	 *  gcc 2.7.2.3 ok, gcc 2.95.2 not ok.
	 */
	foo = *((char *const *) &cfoo);

	return (foo);
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]