Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!ames!ncar!boulder!sunybcs!rutgers!bellcore!texbell!uhnix1!sugar!ficc!walker From: walker@ficc.uu.net (Walker Mangum) Newsgroups: comp.lang.c Subject: Re: Why are character arrays special (equal rights for structs) Summary: try this if you thing char *msg and char msg[] are the same! Message-ID: <3033@ficc.uu.net> Date: 7 Feb 89 22:37:40 GMT References: <19742@uflorida.cis.ufl.EDU> <15833@mimsy.UUCP> Organization: Adytum, Inc. Lines: 58 In article <15833@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) writes: > In article <19742@uflorida.cis.ufl.EDU> thoth@beach.cis.ufl.edu > From: chris@umcp-cs.UUCP (Chris Torek) > > In article <138@darth.UUCP> gary@darth.UUCP (Gary Wisniewski) writes: > >As far as your question about "char *help[]" and "char **help": the two > >forms are IDENTICAL to virtually every C compiler (that's worth its > >salt). Arrays in C are merely special cases of pointers. In other > >words, both forms are correct. > [ K&R quotes deleted ] > char msg0[] = "Hello, world"; > char *msg1 = "Hello, world"; > > Given both declarations, > > printf("%s\n", msg0); > > and > > printf("%s\n", msg1); > > produce the same output. Yet msg0 and msg1 are not the same: > > printf("%d %d\n", sizeof (msg0), sizeof (msg1)); > An important difference is, for any C compiler "that's worth its salt", msg0 may not *not* be used as an lvalue! Try this on your compiler: char msg0[] = "Hello, world"; char *msg1 = "Hello, world"; main(argc,argv) int argc; char *argv[]; { msg1 = msg0; /* this is ok - msg1 is a pointer, a legal "lvalue" */ msg0 = msg1; /* this better fail if your compiler is "worth its salt"! */ /* msg0 is the address of an array, and may not be */ /* reassigned. In K&R terms, it may be used only as an */ /* "rvalue", not an "lvalue" */ } I get the following: x.c(10) : error 106: `=' : left operand must be lvalue -- Walker Mangum | Adytum, Incorporated phone: (713) 333-1509 | 1100 NASA Road One UUCP: uunet!ficc!walker (walker@ficc.uu.net) | Houston, TX 77058 Disclaimer: $#!+ HAPPENS