linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Mariano Moreyra" <moremari@aca.org.ar>
To: 'Massimiliano Cialdi' <cialdi@firenze.net>,
	'linux-c-programming' <linux-c-programming@vger.kernel.org>
Subject: RE: const char * vs char[]
Date: Tue, 23 Mar 2004 11:52:12 -0300	[thread overview]
Message-ID: <000f01c410e6$6d7197e0$0c81640a@aca.org.ar> (raw)
In-Reply-To: <20040323151902.000048da.cialdi@firenze.net>

No... "char*" and "char []" are synonyms.
But in this case, you were having a warning because you were passing a
"const char *" to a function that expected a "char *" so the warning was
about the "const" qualifier.
If you have a code like this you wont have any warning at all

#include <stdio.h>
char *str = "pippo";    <---- Note there is no "const" quailfier anymore
int main(void)
{
  void stampa(char s[]);
  stampa(str);
  return 0;
}
void stampa(char s[])
{
 printf("%s\n", s);
}

So, "char[]" and "char*" are synonyms indeed.


-----Mensaje original-----
De: linux-c-programming-owner@vger.kernel.org
[mailto:linux-c-programming-owner@vger.kernel.org]En nombre de
Massimiliano Cialdi
Enviado el: Martes, 23 de Marzo de 2004 11:19
Para: linux-c-programming
Asunto: Re: const char * vs char[]


On Tue, 23 Mar 2004 10:44:36 -0300
"Mariano Moreyra" <moremari@aca.org.ar> wrote:

> I think that the problem is not a difference between "char*" and
> "char[]" The problem is that stampa is receiving a "char[]" and you
> are passing a"const char*" as the arg.
> The "qualifiers from pointer targer type" refers to the "const" part
> of the"const char*" declaration I belive.
> If you declare stampa like this:
>
> void stampa(const char s[]);
>
> you won't have this warning anymore.
so what is a synonym of char[]? Maybe "char (const *)"?

thanks
--
Massimiliano Cialdi
cialdi@firenze.net
m.cialdi@oksys.it
-
To unsubscribe from this list: send the line "unsubscribe
linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


  reply	other threads:[~2004-03-23 14:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-23 12:01 const char * vs char[] Massimiliano Cialdi
2004-03-23 12:19 ` Glynn Clements
2004-03-23 13:44 ` Mariano Moreyra
2004-03-23 14:19   ` Massimiliano Cialdi
2004-03-23 14:52     ` Mariano Moreyra [this message]
2004-03-23 17:04       ` Jan-Benedict Glaw
2004-03-23 20:26         ` Glynn Clements
2004-03-23 20:37       ` Glynn Clements

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='000f01c410e6$6d7197e0$0c81640a@aca.org.ar' \
    --to=moremari@aca.org.ar \
    --cc=cialdi@firenze.net \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=mariano_moreyra@aca.org.ar \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).