Mail Archives: djgpp/2000/11/30/15:36:37
Andrew Clark a écrit dans le message <3a267c5f DOT 0 AT news DOT syr DOT edu>...
>bige.c:15: warning: passing arg 2 of 'mem_err' dicards qualifiers from
>pointer target type
>
>line 15:
>
>mem_err("could not create %s\n", names_east[i]);
>
>where mem_err is a function taking 2 char *'s and returning void.
In other words :
void mem_err(char *, char *)
>names_east is a static const char *[].
>what does this warning mean?
It means that you are playing with fire.
The mem_err() function is designed to accept read-write parameters. It means
that the parameters *must* be read-write.
You have two risky business here:
static const char *names_east[]=
{
"azer",
"azer",
"azer",
};
mem_err("could not create %s\n", names_east[i]);
1 - You put a string literal to a char*.
2 - You put a constant string literal to a char*.
As the function is allowed to change the values of the strings, anything can
happen.
If you want a function to accept pointer to const, you must declare it's
parameter pointer to const:
void mem_err(char const *, char const *)
Now see wether the function can be compiled or not. If not, it means that it
attempt to modify a constant data.
--
-hs- Tabs out, spaces in.
CLC-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
ISO-C Library: http://www.dinkum.com/htm_cl
FAQ de FCLC : http://www.isty-info.uvsq.fr/~rumeau/fclc
- Raw text -