From: naisbodo Newsgroups: comp.lang.c,comp.os.msdos.djgpp Subject: Re: what's this mean? Date: 30 Nov 2000 17:07:51 GMT Organization: http://www.naisbodo.com/ Lines: 52 Message-ID: <9061h7$oq6$1@bob.news.rcn.net> References: <3a267c5f DOT 0 AT news DOT syr DOT edu> X-Trace: PTooG1kMa2WzUi/h+HQcALnz0XXbBF0XRmsXx3Uev08= X-Complaints-To: abuse AT rcn DOT com NNTP-Posting-Date: 30 Nov 2000 17:07:51 GMT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com In comp.lang.c Andrew Clark 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 /* Nasal demons know no limits! */ #include #include 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/