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

From: naisbodo <naisbodo AT enteract DOT com>
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 <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