delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/11/30/17:18:21

X-Originating-IP: [24.167.46.88]
From: "Tom Hutto" <huttothomas AT hotmail DOT com>
To: <djgpp AT delorie DOT com>
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: <OE36PLWMt2oXeExPKpQ000064bc@hotmail.com>
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" <naisbodo AT enteract DOT com>
Newsgroups: comp.lang.c,comp.os.msdos.djgpp
To: <djgpp AT delorie DOT com>
Sent: Thursday, November 30, 2000 11:07 AM
Subject: Re: what's this mean?


| 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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019