X-Originating-IP: [24.167.46.88] From: "Tom Hutto" To: References: <3a267c5f DOT 0 AT news DOT syr DOT edu> <9061h7$oq6$1 AT bob DOT news DOT rcn DOT net> Subject: Re: what's this mean? Date: Thu, 30 Nov 2000 16:13:55 -0600 X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Message-ID: X-OriginalArrivalTime: 30 Nov 2000 22:13:45.0592 (UTC) FILETIME=[CE5E0780:01C05B1A] Reply-To: djgpp AT delorie DOT com Hmmm, I know a couple of very nice compilers that would be rude enough to call this sort of thing and ERROR and refuse to complete the compile step. ----- Original Message ----- From: "naisbodo" Newsgroups: comp.lang.c,comp.os.msdos.djgpp To: Sent: Thursday, November 30, 2000 11:07 AM Subject: Re: what's this mean? | 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/ |