Need an opinion from C++ folks
Mark Mitchell
mark@markmitchell.com
Wed Oct 28 17:28:00 GMT 1998
You asked:
Is this a bug or not?
#include <stdio.h>
int foo(char *bar) {
printf("%s\n",bar);
}
int main() {
int x;
x=0;
foo("bar");
foo(x ? "bar" : "foobar");
}
[root@bobby /]# g++ -o foo foo.c
foo.c: In function `int main()':
foo.c:13: passing `const char *' as argument 1 of `foo(char *)'
discards qualifiers
The bug is that the first call is accepted. String literals are of
type `const char [n]' where n is the number of characters, including
the trailing '\0'. I suspect that there is some leniency code in the
compiler that allows the first call, but not the second. The code
provided is not ISO compliant.
The right thing to do, IMO, is remove this hackery, and issue the
error message on both calls. There may be those, however, that feel
that backwards compatibility is more important, despite this
inconsistency.
--
Mark Mitchell mark@markmitchell.com
Mark Mitchell Consulting http://www.markmitchell.com
More information about the Gcc-bugs
mailing list