delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/11/30/15:36:37

From: "-hs-" <email DOT invalid AT server DOT invalid>
Newsgroups: comp.lang.c,comp.os.msdos.djgpp
Subject: Re: what's this mean?
Date: Thu, 30 Nov 2000 21:34:43 +0100
Lines: 61
Message-ID: <906dla$lj3$1@news5.isdnet.net>
References: <3a267c5f DOT 0 AT news DOT syr DOT edu>
NNTP-Posting-Host: r79m66.cybercable.tm.fr
X-Trace: news5.isdnet.net 975616490 22115 195.132.79.66 (30 Nov 2000 20:34:50 GMT)
X-Complaints-To: abuse AT isdnet DOT net
NNTP-Posting-Date: 30 Nov 2000 20:34:50 GMT
X-Newsreader: Microsoft Outlook Express 4.72.3110.5
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Andrew Clark a écrit dans le message <3a267c5f DOT 0 AT news DOT syr DOT edu>...
>bige.c:15: warning: passing arg 2 of 'mem_err' dicards qualifiers from
>pointer target type
>
>line 15:
>
>mem_err("could not create %s\n", names_east[i]);
>
>where mem_err is a function taking 2 char *'s and returning void.


In other words :

void mem_err(char *, char *)

>names_east is a static const char *[].


>what does this warning mean?


It means that you are playing with fire.


The mem_err() function is designed to accept read-write parameters. It means
that the parameters *must* be read-write.

You have two risky business here:

static const char *names_east[]=
{
   "azer",
   "azer",
   "azer",
};

mem_err("could not create %s\n", names_east[i]);

1 - You put a string literal to a char*.
2 - You put a constant string literal to a char*.

As the function is allowed to change the values of the strings, anything can
happen.

If you want a function to accept pointer to const, you must declare it's
parameter pointer to const:

void mem_err(char const *, char const *)

Now see wether the function can be compiled or not. If not, it means that it
attempt to modify a constant data.

--
-hs-    Tabs out, spaces in.
CLC-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
ISO-C Library: http://www.dinkum.com/htm_cl
FAQ de FCLC : http://www.isty-info.uvsq.fr/~rumeau/fclc




- Raw text -


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