Mail Archives: djgpp/2000/11/30/12:21:34
In comp.lang.c Andrew Clark <anclark AT syr DOT edu> wrote:
> mem_err("could not create %s\n", names_east[i]);
> bige.c:15: warning: passing arg 2 of 'mem_err' dicards qualifiers from
> pointer target type
> what does this warning mean?
Let me give you a full example:
#include <limits.h> /* Nasal demons know no limits! */
#include <stdlib.h>
#include <stdio.h>
typedef unsigned char uchar;
void
mangle(uchar *foo)
{
/* Hahaha, now I shall mangle() poor unsuspecting foo! */
for (*foo; *foo; *foo++)
*foo = (int)foo % UCHAR_MAX;
}
int
main(void)
{
/* Gee! I sure hope const protects foo from being mangled! */
const uchar foo[] = "Hello, kind world that would never mangle me!";
printf("%s\n",foo);
mangle(foo);
printf("%s\n",foo); /* Oh no!! Poor foo! She was my favorite uchar[] */
return EXIT_FAILURE; /* We've failed! */
}
foo is qualified const. But mangle doesn't take a const uchar! So it
discards the qualifier. The result? foo ends up being mangled, even
though you declared it const!
> where mem_err is a function taking 2 char *'s and returning void.
> names_east is a static const char *[].
It's warning you, in case you value its constness. If mem_err won't
modify the contents of that char *, perhaps you should const-qualify it
in your prototype.
--
naisbodo AT enteract DOT com
http://www.naisbodo.com/
- Raw text -