Path: utzoo!attcan!uunet!husc6!rutgers!gatech!udel!lesh@oscar.ccm.udel.edu From: lesh@oscar.ccm.udel.edu Newsgroups: comp.sys.mac.programmer Subject: String Initialization Problem in LSC Message-ID: <6075@louie.udel.EDU> Date: 22 Dec 88 15:36:44 GMT Sender: usenet@udel.EDU Distribution: na Organization: University of Delaware, CCM Lines: 73 I'm having a problem with initializing string constants in LightSpeed C. I have generated a short program that exhibits the problem and is presented below. --------------------------------------------------------------------------- File: Test.c --------------------------------------------------------------------------- #include extern char *emptyString; extern char *testString1,*testString2; main() { printf("%08lx: '%s'\n",emptyString,emptyString); printf("%08lx: '%s'\n",testString1,testString1); printf("%08lx: '%s'\n",testString2,testString2); } --------------------------------------------------------------------------- File: Test Library.c --------------------------------------------------------------------------- char *emptyString=""; char *testString1="Hello1"; char testString2[]="Hello2"; --------------------------------------------------------------------------- If you compile these two files in a project with MacTraps and stdio you will get the following output before the program hangs. 000f72b6: '' 000f72b8: 'Hello1' 48656c6c: '| In the second edition of "C: A Reference Manual" by Harbison and Steele, they claim that strings can be intializes as follows: static char x[5]="ABCD"; static char str[]="ABCDEF"; So why doesn't this program compile correctly in LSC 3.01? As is turns out, if you modify the file Test.c as follows and remove the Test Library.c file from the project you will get the correct results. --------------------------------------------------------------------------- File: Test.c --------------------------------------------------------------------------- #include char *emptyString=""; char *testString1="Hello1"; char testString2[]="Hello2"; main() { printf("%08lx: '%s'\n",emptyString,emptyString); printf("%08lx: '%s'\n",testString1,testString1); printf("%08lx: '%s'\n",testString2,testString2); } --------------------------------------------------------------------------- Thanks, Richard Lesh CCM University of Delaware Newark, DE 19716 302-451-1519 Internet: LESH@OSCAR.CCM.UDEL.EDU BITNET: LESH%OSCAR.CCM.UDEL.EDU@CUNYVM ARPANET: LESH@OSCAR.CCM.UDEL.EDU