Path: utzoo!attcan!uunet!lll-winken!ames!pasteur!ucbvax!hplabs!hp-pcd!hpmcaa!marco From: marco@hpmcaa.HP.COM (Marco Dalla-Gasperina) Newsgroups: comp.sys.ibm.pc Subject: Re: Another msc 5.1 bug Message-ID: <200019@hpmcaa.HP.COM> Date: 9 Jan 89 18:29:08 GMT References: <139@smsdpg.uu.net> Organization: HP McMinville Division Lines: 49 / hpmcaa:comp.sys.ibm.pc / news@oberon.USC.EDU (USENET News) / 2:34 pm Jan 6, 1989 / In article <139@smsdpg.uu.net> seg@smsdpg.UUCP (Scott Garfinkle) says: >I just ran across a neat new (?) bug in MSC5.1: >fun() { > extern int * const a; > int * const b = a; > b[0] = 1; >} >produces "foo.c(5) : error C2166: lval specifies 'const' object" >In other words, you can't use a const pointer to a >non-const chunk of memory. Scott is right. This is a bug. In article <200015@hpmcaa.HP.COM> marco@hpmcaa.HP.COM (Marco Dalla-Gasperina) says: >I'm not sure of this, but... > int * const a means the value (*a) is constant > int const * a means the value (a) is constant >Seems backwards but thats what the manual says! Marco is wrong. The manual says: "int const * p" declares a pointer to const, cf. sec. 4.4 (p. 62) and sec. 4.4.6 (p. 74), while "int * const p" declares a constant pointer to int, cf. sec. 4.5.5 (p. 81) and sec. 4.7.1 (p. 90). This is consistent with Harbison & Steele, 2nd ed, sec 11.4.3: "int * const const_pointer; const int * pointer_to_const;" Perhaps intentionally H&S do not use the form "int const *" as possibly misleading. Related to this topic, why isn't this example from H&S p.265 illegal? const int *p; *p = 5; /* Legal, but ... */ Christopher M. Gould Internet: gould@physics.usc.edu (128.125.1.194) Dept. of Physics Arpanet: gould@usc-physics.arpa Univ. of Southern Calif. UUCP: ...{uunet,sdcrdcf}!oberon!physics!gould Los Angeles, CA 90089-0484 Phone: (213)743-8521 ---------- Arrrggggh! I hate it when I'm wrong! My apologies for incorrectly reading the manual... I thought it sounded weird when I was writing it but I didn't pay enough attention to my hackers intuition. I here that 5% of the adult population in this country is illiterit (er.. ileterate, ilitterate)... can't read. Maybe I'm one of them. apologies, marco