Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!tut.cis.ohio-state.edu!ucbvax!hplabs!hp-pcd!hpcvlx!billf From: billf@hpcvlx.cv.hp.com (Bill F. Faus) Newsgroups: comp.sys.mac.programmer Subject: Think C: Initialization puzzle?? Message-ID: <101780005@hpcvlx.cv.hp.com> Date: 22 Mar 90 22:57:55 GMT Organization: Hewlett-Packard Co., Corvallis, OR, USA Lines: 43 Question: Can someone help me understand why this initialization is legal: char a[] = "hunky dory"; char * p = a; char b = 'x'; char * q = &b; And this isn't: char * q = "wishy washy"; char * p = q; This question has come up as I want to initalize 120K of string data and use the STRS option of Think C so I don't have to worry about data segments. As in: char * bit_map_A = "\012\013\014...."; char * bit_map_B = "\230\231\232...."; ......... char * bit_map_ZZ = "\001\002\003...."; If instead I had used char arrays instead of char pointers: char * bit_map_A[] = "\012\013\014...."; Then I could subsequently intialize an array of bitmaps like: char * bit_map_ptr[] = {bit_map_A, bit_map_B, ...., bit_map_ZZ}; The 'bind' I get in is that arrays intialized with string literals get allocated in the main data segment, so I run out of room but I CAN use the nifty feature of referring to the array name in subsequent initialization statments. Whereas pointers initialized to string literals get allocated to the automatic STRS data segments but I CANNOT refer to the pointer names in subsequent initialization statements. --------------- billf@cv.hp.com