Path: utzoo!utgpu!attcan!uunet!lll-winken!ames!husc6!cs.utexas.edu!sm.unisys.com!oberon!news From: news@oberon.USC.EDU (USENET News) Newsgroups: comp.sys.ibm.pc Subject: Re: Another msc 5.1 bug Summary: Compiler contradicts manual Keywords: msc Message-ID: <14495@oberon.USC.EDU> Date: 6 Jan 89 22:34:05 GMT References: <139@smsdpg.uu.net> <200015@hpmcaa.HP.COM> Reply-To: gould@physics.usc.edu (Christopher Gould) Organization: University of Southern California, Los Angeles, CA Lines: 37 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