typedef-ing an array
Roger Meunier
roger at zuken.co.jp
Sat Jun 30 05:50:12 AEST 1990
In article <78633 at srcsip.UUCP> pclark at SRC.Honeywell.COM (Peter Clark) writes:
> What I meant was, why doesn't this work:
>
>-----------------------------------------
>
>#include <stdio.h>
>
>typedef char foo[29];
>
>/* a string with 28 chars, add one for the NULL byte */
>foo bar = "Hello World, this is my test";
>
>void
> main()
>{
> bar = "Silly old me";
> printf("%s\n",bar);
>}
>--------------------------------------------------
The variable "bar" is declared as a static string. That is not the
same as declaring "char* bar" which is necessary for the assignment
statement. I don't believe standard C even hints that strings are
copied by assignment statements. A *pointer* to the literal string
is assigned to lhs, and in your example bar's type won't accept a
pointer. Try 'char* bar = "Hello World, this is my test";' instead.
Clear as mud?
--
Roger Meunier @ Zuken, Inc. Yokohama, Japan (roger at zuken.co.jp)
More information about the Comp.lang.c
mailing list