arrays - Why do I get a warning trying to pass a 'char (*c)[6]' to a function expecting a 'const char (*c)[6]'? -


i know char ** vs const char ** thing (like described in c faq) can't see scenario doing pointer arrays lead content inside arrays being modified.

my code:

void fun(const char (*p)[6]) {     printf("%s", p[0]); }  int main(int argc, char *argv[]) {     char a[6] = "hello";     char (*c)[6];      c = &a;      fun(c); } 

gives below output when compiled gcc:

test.c:17:9: warning: passing argument 1 of 'fun' incompatible pointer type test.c:5:10: note: expected 'const char (*)[6]' argument of type 'char (*)[6]' 

the question here somehow related has no answer far. compiler being paranoïd , way rid of warning explicitly cast ? or there chance can go wrong ?

it quirk of c language specification. example, char ** const char *const * conversion safe const-correctness point of view, yet prohibited in c.

this quirk of const-correctness rules "fixed" in c++ language, c continues stick original specification in regard.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -