Difference between "char *arr" and "char arr[]"
Jeff d'Arcy
jdarcy at encore.com
Sun Sep 23 04:58:44 AEST 1990
In case nobody else has mentioned it (I came in late on this one), there
is a difference between *x and x[] besides allocation and semantics for
globals: sizeof(). A lot of times I've been tempted to write
static char *message = "hello";
/* ... */
write(fd,message,sizeof(message));
within a routine. Obviously this won't work, but
static char message[] = "hello";
will. It's amazing how easy it is to forget this little detail and how
many times I've seen it done. Usuaully it's much more insidious than
this example.
--
Jeff d'Arcy, Generic Software Engineer - jdarcy at encore.com
Nothing was ever achieved by accepting reality
More information about the Comp.lang.c
mailing list