L
lovecreatesbea...
Gcc only gives out a warning: `assignment discards qualifiers from
pointer target type' against code such as following:
$ type a.c
int main(void)
{
const char *pc;
char *p = pc;
return 0;
}
$ gcc -std=c99 -W -Wall a.c
a.c: In function `main':
a.c:4: warning: initialization discards qualifiers from pointer target
type
a.c:4: warning: unused variable `p'
$
`C: A Reference Manual, 5th', sec. 5.11.1 states that: `... In
standard C, the presence of any type qualifiers changes the
type: ...'. It says in sec 5.11.6: `Two (similarly qualified) pointer
types are compatible if they point to compatible types.'
In the above code snippet, `const char' and `char' are not qualified
similarly, they're not compatible types. pc and p are not compatible
pointers for they point to incompatible types. So, why isn't the
initialization above an error?
pointer target type' against code such as following:
$ type a.c
int main(void)
{
const char *pc;
char *p = pc;
return 0;
}
$ gcc -std=c99 -W -Wall a.c
a.c: In function `main':
a.c:4: warning: initialization discards qualifiers from pointer target
type
a.c:4: warning: unused variable `p'
$
`C: A Reference Manual, 5th', sec. 5.11.1 states that: `... In
standard C, the presence of any type qualifiers changes the
type: ...'. It says in sec 5.11.6: `Two (similarly qualified) pointer
types are compatible if they point to compatible types.'
In the above code snippet, `const char' and `char' are not qualified
similarly, they're not compatible types. pc and p are not compatible
pointers for they point to incompatible types. So, why isn't the
initialization above an error?