Ansi violation ?
Tue Sep 5 10:23:00 GMT 2000
Marc Olzheim <firstname.lastname@example.org> writes:
> gcc 2.95.2 on FreeBSD 4.1
> For 184.108.40.206 it works ok.
> gcc -c -o const.o -Wcast-qual -ansi const.c
Warn whenever a pointer is cast so as to remove a type
qualifier from the target type. For example, warn if a const
char * is cast to an ordinary char *.
If you remove the flag -Wcast-qual, the warning disappears.
> 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.
> char *
> char *foo;
> const char *cfoo = "bar";
> /* From http://www.eskimo.com/~scs/C-faq/q11.10.html:
> * References: ANSI Sec. 220.127.116.11, Sec. 18.104.22.168, Sec. 3.5.3
> * ISO Sec. 22.214.171.124, Sec. 126.96.36.199, Sec. 6.5.3
> * H&S Sec. 7.9.1 pp. 221-2
> * Use -Wcast-qual with gcc.
> * gcc 188.8.131.52 ok, gcc 2.95.2 not ok.
> foo = *((char *const *) &cfoo);
> return (foo);
More information about the Gcc-bugs