Path: utzoo!attcan!uunet!steinmetz!davidsen From: davidsen@steinmetz.ge.com (William E. Davidsen Jr) Newsgroups: comp.lang.c Subject: Re: Use of Const keyword in ANSI C Message-ID: <12098@steinmetz.ge.com> Date: 8 Sep 88 18:37:00 GMT References: <441@optilink.UUCP> Reply-To: davidsen@crdos1.UUCP (bill davidsen) Organization: General Electric CRD, Schenectady, NY Lines: 26 In article <441@optilink.UUCP> cramer@optilink.UUCP (Clayton Cramer) writes: | I've defined a structure: | | typedef struct Tag | { | const int A; | short B; | const char* C; | } TestType; | | TestType Test1 = {10, 10, "test case"}; | | Test1.A = 5; /* compiler complains about this -- good */ | Test1.B = 20; /* compiler accepts this -- fine */ | Test1.C = "not a test case"; /* compiler accepts this -- bad */ I think it's right. You have a "pointer to const char" (I think) and a quoted string is (can be?) a const string, so it works. After the first assignment try Test1.C[2] = 'x'; and see if it tells you you can't modify a const string. -- bill davidsen (wedu@ge-crd.arpa) {uunet | philabs}!steinmetz!crdos1!davidsen "Stupidity, like virtue, is its own reward" -me