473,382 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

mutable data structures

The C++ language specification provides the key word "mutable" that is
not available in the C99 standard.
Will it be imported to reduce any incompatibilities?
http://david.tribble.com/text/cdiffs...99-cpp-keyword
http://www.inf.uni-konstanz.de/~kueh...html#faq-18.13

Regards,
Markus

Nov 15 '05 #1
18 2555
In article <11**********************@g49g2000cwa.googlegroups .com>,
Ma************@web.de writes
The C++ language specification provides the key word "mutable" that is
not available in the C99 standard.
Will it be imported to reduce any incompatibilities?


I doubt it. why would C want to change simply to reduce incompatibilitys
with C++?

As it is most compilers do not support C99 (OK one claims to support it)
but the vast majority of C compilers are still at C90+ a few bits. SO
even if mutable and other C++ things are put into the C0* standard there
is no guarantee that it will be implemented.

You will get the companies who produce C/C++ compilers who will do it
but those that produce just C compilers will probably not unless their
customers start clamouring for it in a way they have not be asking for
C99.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Nov 15 '05 #2
On 10 Jul 2005 04:41:53 -0700, Ma************@web.de
<Ma************@web.de> wrote:
The C++ language specification provides the key word "mutable" that is
not available in the C99 standard.
Will it be imported to reduce any incompatibilities?
http://david.tribble.com/text/cdiffs...99-cpp-keyword
http://www.inf.uni-konstanz.de/~kueh...html#faq-18.13


Why should C provide it? It makes sense in C++ because you can have
member functions which operate on a 'const' object but which need to
alter data private to that object (so to external view nothing has
changed, but some internal data has been altered), but in C all fields
are public anyway so I don't see how it would be useful.

For instance, having a 'mutable' member would preclude the structure
being put into read-only memory (when delared as const), which would be
a definite disadvantage for many embedded systems.

It isn't a goal of C to remain compatible with C++ or of C++ to remain
compatible with C (for instance it would be useful to have long long and
the sized arithmetic types in C++) except via the extern "C" linkage.

Chris C
Nov 15 '05 #3
Ma************@web.de wrote:
The C++ language specification provides the key word "mutable" that is
not available in the C99 standard.
Will it be imported to reduce any incompatibilities?
http://david.tribble.com/text/cdiffs...99-cpp-keyword
http://www.inf.uni-konstanz.de/~kueh...html#faq-18.13

Regards,
Markus


There is no effort that I know of by either the C community nor the C++
community to make the two languages more compatible. In designing C++ BS
started with familiar C and built his own new language. As time goes on
and the two languages evolve, new features of one might find their way
into the other. This is not about compatibility.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 15 '05 #4


Chris Croughton schrieb:
On 10 Jul 2005 04:41:53 -0700, Ma************@web.de
<Ma************@web.de> wrote:
The C++ language specification provides the key word "mutable" that is
not available in the C99 standard.
Will it be imported to reduce any incompatibilities?
http://david.tribble.com/text/cdiffs...99-cpp-keyword
http://www.inf.uni-konstanz.de/~kueh...html#faq-18.13
Why should C provide it? It makes sense in C++ because you can have
member functions which operate on a 'const' object but which need to
alter data private to that object (so to external view nothing has
changed, but some internal data has been altered), but in C all fields
are public anyway so I don't see how it would be useful.


Public accessibility and visibility does not affect the constant state
of an attribute.
Would you like to be able to specify that a data field can never be
const and must always be writeable?

For instance, having a 'mutable' member would preclude the structure
being put into read-only memory (when delared as const), which would be
a definite disadvantage for many embedded systems.


Can you imagine that any data like cached values must not be stored
into write-protected memory?
Do you try to cast the constness away in such environments?

Regards,
Markus

Nov 15 '05 #5
> There is no effort that I know of by either the C community nor the C++
community to make the two languages more compatible. In designing C++ BS
started with familiar C and built his own new language. As time goes on
and the two languages evolve, new features of one might find their way
into the other. This is not about compatibility.


I would like to see more cooperation in feature addition.

Regards,
Markus

Nov 15 '05 #6
Ma************@web.de wrote:
There is no effort that I know of by either the C community nor the C++
community to make the two languages more compatible. In designing C++ BS
started with familiar C and built his own new language. As time goes on
and the two languages evolve, new features of one might find their way
into the other. This is not about compatibility.


I would like to see more cooperation in feature addition.


I would like not to see unnecessary keywords added to C. Being 79%
incompatible with C++ rather than 80% is not a goal that makes sense.

Richard
Nov 15 '05 #7
On 11 Jul 2005 05:59:02 -0700, Ma************@web.de
<Ma************@web.de> wrote:
Chris Croughton schrieb:
On 10 Jul 2005 04:41:53 -0700, Ma************@web.de
<Ma************@web.de> wrote:
> The C++ language specification provides the key word "mutable" that is
> not available in the C99 standard.
> Will it be imported to reduce any incompatibilities?
> http://david.tribble.com/text/cdiffs...99-cpp-keyword
> http://www.inf.uni-konstanz.de/~kueh...html#faq-18.13
Why should C provide it? It makes sense in C++ because you can have
member functions which operate on a 'const' object but which need to
alter data private to that object (so to external view nothing has
changed, but some internal data has been altered), but in C all fields
are public anyway so I don't see how it would be useful.


Public accessibility and visibility does not affect the constant state
of an attribute.
Would you like to be able to specify that a data field can never be
const and must always be writeable?


No, I see no need for it in C. As I said, in C++ there is more need for
it, and it is normally kept protected from user visibility.
For instance, having a 'mutable' member would preclude the structure
being put into read-only memory (when delared as const), which would be
a definite disadvantage for many embedded systems.


Can you imagine that any data like cached values must not be stored
into write-protected memory?


Huh? If it's modifiable it can't be in write-protected memory,
obviously.
Do you try to cast the constness away in such environments?


I don't cast constness away in any environments (except for certain
broken interfaces, and that's been so long ago that I've forgotten why
we had to do that, something to do with a callback which was specified
as const incorrectly).

Chris C
Nov 15 '05 #8
On 11 Jul 2005 05:59:02 -0700, Ma************@web.de
<Ma************@web.de> wrote:
There is no effort that I know of by either the C community nor the C++
community to make the two languages more compatible. In designing C++ BS
started with familiar C and built his own new language. As time goes on
and the two languages evolve, new features of one might find their way
into the other. This is not about compatibility.


I would like to see more cooperation in feature addition.


Indeed, I would like to see several things in C propagated into C++. In
particular long long and the named-width types in stdint.h. However,
propagating features just because they are there is not a good plan.

Chris C
Nov 15 '05 #9
In article <42****************@news.xs4all.nl>, Richard Bos
<rl*@hoekstra-uitgeverij.nl> writes
Ma************@web.de wrote:
> There is no effort that I know of by either the C community nor the C++
> community to make the two languages more compatible. In designing C++ BS
> started with familiar C and built his own new language. As time goes on
> and the two languages evolve, new features of one might find their way
> into the other. This is not about compatibility.


I would like to see more cooperation in feature addition.


I would like not to see unnecessary keywords added to C. Being 79%
incompatible with C++ rather than 80% is not a goal that makes sense.

Richard


I agree the C and C++ are separate languages that share a common
ancestor.

C and C++ are likely to develop on separate directions for differing
reasons. For those people who need to interface to C or use C libraries
I suggest that they port the C code to a C subset of C++ that their C++
compiler supports.

Then write and maintain all the "c" with the C++ compiler.

Eventually that hybrid language c/C++ will die out.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Nov 15 '05 #10
In article <sl******************@ccserver.keris.net>, Chris Croughton
<ch***@keristor.net> writes
On 11 Jul 2005 05:59:02 -0700, Ma************@web.de
<Ma************@web.de> wrote:
There is no effort that I know of by either the C community nor the C++
community to make the two languages more compatible. In designing C++ BS
started with familiar C and built his own new language. As time goes on
and the two languages evolve, new features of one might find their way
into the other. This is not about compatibility.


I would like to see more cooperation in feature addition.


Indeed, I would like to see several things in C propagated into C++. In
particular long long and the named-width types in stdint.h. However,
propagating features just because they are there is not a good plan.

Chris C


We agree for once ( I won't let it happen again :-)
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Nov 15 '05 #11
> Huh? If it's modifiable it can't be in write-protected memory,
obviously.


What do you do if a few mutable elements are embedded into a larger
constant data structure?

Regards,
Markus

Nov 15 '05 #12
Ma************@web.de writes:
Huh? If it's modifiable it can't be in write-protected memory,
obviously.


What do you do if a few mutable elements are embedded into a larger
constant data structure?


If a data structure has mutable elements, it's not constant, and you
can't put it in write-protected memory -- unless the mutable elements
are disjoint.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #13
On 12 Jul 2005 05:00:45 -0700, Ma************@web.de
<Ma************@web.de> wrote:
Huh? If it's modifiable it can't be in write-protected memory,
obviously.


What do you do if a few mutable elements are embedded into a larger
constant data structure?


If an element can be changed then the structure isn't constant. Simple,
really.

Chris C
Nov 15 '05 #14
> If a data structure has mutable elements, it's not constant, and you
can't put it in write-protected memory -- unless the mutable elements
are disjoint.


Do you distinguish between logical and physical constness?

Regards,
Markus

Nov 15 '05 #15
> If a data structure has mutable elements, it's not constant, and you
can't put it in write-protected memory -- unless the mutable elements
are disjoint.


Do you distinguish between logical and physical constness?

Regards,
Markus

Nov 15 '05 #16
On Wed, 13 Jul 2005 05:38:05 -0700, Markus.Elfring wrote:
If a data structure has mutable elements, it's not constant, and you
can't put it in write-protected memory -- unless the mutable elements
are disjoint.


Do you distinguish between logical and physical constness?


In the context of whether a structure can be placed in write-protected
memory only physical constness matters. Logical constness is more natural
in the context of encapsulation provided e.g. by C++ classes because you
can hide the non-const bits and present an interface that appears const.
Of course you can do similar things in C, it is a question of how much
this helps in a normal/natural C coding style, whatever that is.

If you want to add mutable to C argue in terms of what value it would add
to the C language, not in terms of compatibility with C++ (although what
I'm replying to here doesn't do that).

Lawrence
Nov 15 '05 #17
> If you want to add mutable to C argue in terms of what value it would add
to the C language, not in terms of compatibility with C++ (although what
I'm replying to here doesn't do that).


I would like to benefit from the capability to distinguish between
logical and physical constness in all data.
Is C++ the only (object-oriented) language that allows to specify that
something can never be constant?

Other (scripting) languages know only mutable/writeable structures by
default. Dynamic checks must be added there to make them appear like
"const" or "read-only".

Regards,
Markus

Nov 15 '05 #18
Ma************@web.de wrote:
If you want to add mutable to C argue in terms of what value it would add
to the C language, not in terms of compatibility with C++ (although what
I'm replying to here doesn't do that).


I would like to benefit from the capability to distinguish between
logical and physical constness in all data.
Is C++ the only (object-oriented) language that allows to specify that
something can never be constant?

Other (scripting) languages know only mutable/writeable structures by
default. Dynamic checks must be added there to make them appear like
"const" or "read-only".


You can fake mutable to a certain degree.
Consider using indirection or const struct within struct (or, if
you must, casting away (const) depending on some flag or hard-coded).
Another possibility is creating appropriate interfaces which get
passed the structures (or pointers to them) as a whole as const and
non-const pointers to the mutable parts. If need be, you even can wrap
that up in some super-structure:
struct super
{
const struct payload *pc;
/* mutable list */
flagtype *internalstuff;
countertype *hiddencounter;
...
};
or, more generally,
struct gen_super {
const struct {unsigned char dummy;} *const_struct;
void *mutables;
}
with appropriate casting (note that pointers to struct types always
have the same size, representation and alignment requirements, so
casting from the dummy struct* type to the desired struct type pointer
is only evil to a limited degree).

However, I am not aware of any straightforward all-purpose pattern
for this.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 15 '05 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Gordon Airport | last post by:
Has anyone suggested introducing a mutable string type (yes, of course) and distinguishing them from standard strings by the quote type - single or double? As far as I know ' and " are currently...
50
by: Dan Perl | last post by:
There is something with initializing mutable class attributes that I am struggling with. I'll use an example to explain: class Father: attr1=None # this is OK attr2= # this is wrong...
5
by: Adam H. Peterson | last post by:
I'm using a private base class as part of the implementation for one of my classes. In my implementation, it holds cached data, and I'd like to be able to call its const member functions from my...
3
by: Ingo Nolden | last post by:
Hi, I try to use const where ever appropriate. In a collection class I am counting the iterators that are out. The counter decrements when an iterator leaves scope or is 'Dispose( )'d While...
6
by: christopher diggins | last post by:
I wrote a dynamic matrix class similar to the one described in TCPL 3rd Edition. Rather than define two separate iterators for const and non-const scenarios I decided to be a lazy bastard and only...
12
by: Water Cooler v2 | last post by:
Are JavaScript strings mutable? How're they implemented - 1. char arrays 2. linked lists of char arrays 3. another data structure I see that the + operator is overloaded for the string class...
5
by: Andreas Beyer | last post by:
There has been quite some traffic about mutable and immutable data types on this list. I understand the issues related to mutable numeric data types. However, in my special case I don't see a...
2
by: subramanian100in | last post by:
I am reading David Musser's "STL Tutorial and Reference Guide" Second Edition. In that book, on pages 68-69, definition has been given that "an iterator can be mutable or constant depending on...
24
by: Steven D'Aprano | last post by:
Sometimes it seems that barely a day goes by without some newbie, or not- so-newbie, getting confused by the behaviour of functions with mutable default arguments. No sooner does one thread...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.