"char *" diff in header & func arg list?

John Love-Jensen eljay@adobe.com
Mon Mar 26 18:26:00 GMT 2007


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



More information about the Gcc-help mailing list