Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!mips!apple!sun-barr!ccut!kogwy!new1!roger From: roger@zuken.co.jp (Roger Meunier) Newsgroups: comp.lang.c Subject: Re: typedef-ing an array Message-ID: Date: 29 Jun 90 19:50:12 GMT References: <78627@srcsip.UUCP> <78633@srcsip.UUCP> Sender: news@new1.zuken.co.jp Organization: ZUKEN Inc. Yokohama, JAPAN Lines: 30 In-reply-to: pclark@SRC.Honeywell.COM's message of 28 Jun 90 23:41:11 GMT In article <78633@srcsip.UUCP> pclark@SRC.Honeywell.COM (Peter Clark) writes: > What I meant was, why doesn't this work: > >----------------------------------------- > >#include > >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@zuken.co.jp)