Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!mailrus!tut.cis.ohio-state.edu!bloom-beacon!husc6!bu-cs!polygen!pablo From: pablo@polygen.uucp (Pablo Halpern) Newsgroups: comp.lang.c Subject: Re: Does extern "const" allocate storage? Message-ID: <136@polygen.UUCP> Date: 30 Mar 88 01:49:37 GMT References: <3117@haddock.ISC.COM> Organization: Polygen Corporation, Waltham, MA Lines: 41 From article <3117@haddock.ISC.COM>, by karl@haddock.ISC.COM (Karl Heuer): > An object which is declared const but not volatile can never be modified by a > correct program. A conforming implementation is allowed to take advantage of > this knowledge, by putting it in read-only memory and/or by inlining it. I disagree. An object that is declared const but not volatile can not be modified within the scope in which the declaration holds. Nowhere does the standard say that such an object is "really constant." The lack of the volatile modifier simply indicates that the object will not be modified "behind the function's back" and therefore can take part in certain optimizations. This does bring up a problem, though. In the standard, a clock register is used as an example of a volatile const. The declaration looked something like: extern const volatile int clock; The meaning of this is explaned that the clock register may not be written to by the program and that if it is read once, the value may be different if it is read again. The question is, doesn't this imply that somewhere there is a function that might look as follows: volatile int clock; void update_clock() /* called on clock interupt */ { clock++; } Here, clock is defined with two different types (const volatile int verses volatile int) in two different scopes. Wouldn't a compiler (or lint) that "sees" both scopes be allowed to complain about this? If so, how could you ever update a const volatile type. (Don't tell me you should do it in assembly language. Avoiding the compiler's type checking is not the issue. The meaning of type modifiers in C is the issue.) In general, are you allowed to declare the same object with different type qualifiers provided that the scopes of the declarations do not overlap? If so, please direct me to the section in the standard that says so. Pablo Halpern | mit-eddie \ Polygen Corp. | princeton \ !polygen!pablo (UUCP) 200 Fifth Ave. | bu-cs / Waltham, MA 02254 | stellar /