Topic: April 1 Suggestion - volatile const


Author: miket@world.std.com (Michael Trachtman)
Date: Mon, 21 Mar 1994 18:54:25 GMT
Raw View
There has been some discussion about how compilers can know if
const data is really const, and can thus be romable. As most of the
readers of this group know, const can be casted away.

A solution (non backward compatible) is to define const as being
really const, i.e. non-castable-away.

We will use the existing keyword "volatile", as a modifier of "const"
to mean that the constness is volatile. In other words:
"volatile const" will means that it is const, but that the constness
may be casted away, (e.g. to handle standard stuff like usage counting, etc.).

I can just see it now:

static volatile const int four = 4;
static volatile const MyClass myclass(23,34);

Homework assignment: Should "volatile const" have a different meaning than
 "const volatile" ?

Extra credit: Does "volatile volatile" means that the volatile
  modifier is itself volatile, and thus that this object
  may really be a const ?

Compare: An alternative approach is to let "const const" means a const which
can not change. And let the current "const" means a const which can be casted
away. Is this a better solution ? Why or why not ?

Practice Question:  consider: typedef  int ((*func)(int))  funcp;
  What are all the places that const and volatile can be added ?
  What does each variation mean ?

Research Problem: Can you write a complete data description language,
   which uses only the keywords: "const", "volatile", "static", "typedef",
      "union", "friend", "virtual", "protected", "void" and "dynamic_cast" ?
   Punctuation chars and symbol-names are also allowed.
   Show how in this language you can put these keywords in any order and
      get a different legal description of data (as long as the parenthesis,
      brackets, braces and other paired delimiters are matched.)

   Hint: Use bitfields.


Michael T.

*****************************
Finally, before anyone flames me,
      please read the subject line for this article.






Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Tue, 22 Mar 1994 14:26:38 GMT
Raw View
In article <Cn136r.5s8@world.std.com> miket@world.std.com (Michael Trachtman) writes:
>There has been some discussion about how compilers can know if
>const data is really const, and can thus be romable. As most of the
>readers of this group know, const can be casted away.
>
>A solution (non backward compatible) is to define const as being
>really const, i.e. non-castable-away.

 This is EXACTLY what the committee has done.
>
>We will use the existing keyword "volatile", as a modifier of "const"
>to mean that the constness is volatile.

 Nope. We invented a new keyword "mutable".
--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
 Maxtal Pty Ltd,      CSERVE:10236.1703
        6 MacKay St ASHFIELD,     Mem: SA IT/9/22,SC22/WG21
        NSW 2131, AUSTRALIA




Author: b91926@fsgi01.fnal.gov (David Sachs)
Date: 21 Mar 1994 16:02:11 -0600
Raw View
Unfortunately, C++ already supports declaring an item
as both const and volatile, and there are legitimate
uses for such a declaration.

One common use for a const volatile object, is to reference
an input-only port of a memeory mapped IO peripheral.