This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: "char *" diff in header & func arg list?
- From: John Love-Jensen <eljay at adobe dot com>
- To: kourama <kourama at teksavvy dot com>, MSX to GCC <gcc-help at gcc dot gnu dot org>
- Date: Mon, 26 Mar 2007 13:08:48 -0500
- Subject: Re: "char *" diff in header & func arg list?
Hi kourama,
These two things are mostly interchangeable for most purposes as a
parameter:
char array[];
char* pointer;
On the caller's side, arg1 degenerates into something that almost is the
same as:
char* const arg1;
C proponents would say this is a good thing. I've been working in C++ long
enough to consider it a bit of a wart (but C++ has far more atrocious warts
than this to worry about), as part of the C legacy.
However, this is an outright mismatch:
extern char array[];
extern char* pointer;
char array[] = "good";
char pointer[] = "bad";
Why? Because an array of characters is not a pointer to an array of
characters. The declaration does not match the definition.
> So, is this a bug, legacy behaviour or is this just another wrinkle in the
sharpei puppy that is C?
In this case, not a wrinkle, not a "legacy C" issue. It is a PEBKAC bug.
HTH,
--Eljay