vendredi 27 février 2015

Why does the compiler complain about the assignment?



While compiling the following code, the compiler produces the warning:


assignment discards ‘const’ qualifier from pointer target type



#include<stdio.h>

int main(void)
{
char * cp;
const char *ccp;
cp = ccp;
}


And this code is ok(no warning).Why?



#include<stdio.h>

int main(void)
{
char * cp;
const char *ccp;
ccp = cp;
}


Edit: Then why isn't this ok?



int foo(const char **p)
{
// blah blah blah ...
}

int main(int argc, char **argv)
{
foo(argv);
}



Aucun commentaire:

Enregistrer un commentaire