This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Ansi violation ?
- To: bug-gcc at gnu dot org
- Subject: Ansi violation ?
- From: Marc Olzheim <marcolz at stack dot nl>
- Date: Mon, 4 Sep 2000 17:10:50 +0200
- Cc: Marc Olzheim <marcolz at stack dot nl>
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);
}