Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uwm.edu!ux1.cso.uiuc.edu!pequod.cso.uiuc.edu!dorner From: dorner@pequod.cso.uiuc.edu (Steve Dorner) Newsgroups: comp.sys.mac.programmer Subject: Re: Char * and char[] Keywords: pointers, arrays Message-ID: <1991Jun14.154923.8754@ux1.cso.uiuc.edu> Date: 14 Jun 91 15:49:23 GMT References: <1569@caslon.cs.arizona.edu> <1991Jun14.132530.12254@terminator.cc.umich.edu> Sender: usenet@ux1.cso.uiuc.edu (News) Organization: University of Illinois at U-C Lines: 44 In article <1991Jun14.132530.12254@terminator.cc.umich.edu> potts@us.cc.umich.edu (Paul Potts) writes: >Why not do the following: > >char name [30] = "\PNo Name"; Cause you can't initialize automatic arrays, for one. 'Sides, strings don't belong in mac programs; resources should be used. (Pedantic but true.) >cp = "\PNo Name"; (cp is implicitly a pointer to char if you do this). No, your statement is an illegal attempt to assign a pointer (to "\PNo Name") to an int (which is what cp be implicitly declared to be, if your compiler engages in implicit behavior (some do, some don't)). > &(theDecker.name[0]) Completely synonymous with theDecker.name; just less efficient notationally (and computationally, if you have an incredibly stupid compiler, which are distressingly common). >you will need to cast it as a pointer to char: > >(char*)&(theDecker.name[0]) Not if "name" is declared as "char name[30]". >If anyone >finds that I am claiming something incorrectly, please declaim a correction >on the net. You've got a decent handle on these things conceptually, it's just the niggling details... And an aside for MPW sufferers: > p = &a; >That is illegal in ANSI C because &a is a pointer to an array but >p is a pointer to an int." But it's required in SADE (they wouldn't call it SADE if it were pleasant, now would they?). :-) -- Steve Dorner, U of Illinois Computing Services Office Internet: s-dorner@uiuc.edu UUCP: uunet!uiucuxc!uiuc.edu!s-dorner