Compiling GCC With a C++ Compiler (g++)

Steven L. Zook SLZook@Qualstar.com
Wed Oct 13 03:47:00 GMT 2004


Pardon me for intruding here. This may not be applicable to your specifics.

C++ does have a construct for write-once storage; construction. For example,

struct sDerf { sDerf( int WriteOnceValue ) : ReadOnlyValue( WriteOnceValue ) {}
               int const ReadOnlyValue;
             };

As far as I know, this is the only "supported" method. The rest are tricks that tunnel around the language by using unions, casting, or pointer aliasing.

As far a language deficiency is concerned, I have always thought that some more modifiers than const and volatile would be useful. Especially for embedded programmers like me. The spelling of the following is not important: only the effect matters.

readonly: class members and friends can write but outsiders can only read. This would eliminate having to write accessor functions.

construct: constructor can modify any number of times in initializer list or in body but all others can only read.

interrupt: acts like volatile in non-interrupt service routines and non-volatile in an ISR (where an ISR is marked by some attribute or perhaps by name).

-----Original Message-----
From: gcc-owner@gcc.gnu.org [mailto:gcc-owner@gcc.gnu.org]On Behalf Of
Zack Weinberg
Sent: Tuesday, October 12, 2004 3:58 PM
To: Gabriel Dos Reis
Cc: Geoffrey Keating; Ranjit Mathew; GCC
Subject: Re: Compiling GCC With a C++ Compiler (g++)


Gabriel Dos Reis <gdr@cs.tamu.edu> writes:

> Geoffrey Keating <geoffk@apple.com> writes:
> | The 'const' is there to indicate that the string should not be changed
> | once the STRING_CST is created;
>
> And how do you create it?

By casting away the const, as is done in build_string.  Or by
constructing the data in memory before giving it the type with the
const qualifier.

How else do you propose to enforce write-once semantics on a data
structure that is, in fact, write-once?  I am definitely with Geoff
here - this should be allowed (or, to rephrase, if C++ has no
construct which allows what we want to do here, that is a language
deficiency).

zw



More information about the Gcc mailing list