Re: Static Read-only array fields in C++

From: Tomas Restrepo \(MVP\) (tomasr_at_mvps.org)
Date: 08/31/04


Date: Mon, 30 Aug 2004 22:09:21 -0500

Hi Mark,

> Thanks fior the reply. I had already suspected that this was impossible in
> C++ .NET 2003.
>
> Just to clarify, this appears only to be a problem relating to managed
> arrays. With other types of objects, the 'const' keyword in the
appropriate
> place seems to do what I want. (The object is still mutable but the
'pointer'
> isn't.)
> If not using arrays, does the 'const' keyword actually result in the
correct
> 'initonly' entry in the metadata, or is it just 'const' as far as the C++
> compiler is concerned but external consumers of this class, implemented in
> different languages, would actually be able to modify this public field.

It depends on where you put it :)
Example, this:
   static String * const empty = S"asdasd";
will generate "initonly". This, otoh:
   static const String * empty = S"asdasd";
won't :)

> Also, any idea why this is an issue with managed arrays, and not other
> managed type in C++? Is this just a quirk with the way the managed array
> syntax was implemented in Managed C++?

I'm not quite sure exactly what the issue is, someone from MS would've to
chime in to answer exactly... It's probably a quirk in the front end, I
guess....

-- 
Tomas Restrepo
tomasr@mvps.org


Relevant Pages

  • [rfc git pull] cpus4096 fixes, take 2
    ... this should result 32.5kB of static const data. ... by sharing all the zero words. ... arrays instead, each 8k bits in size. ...
    (Linux-Kernel)
  • Re: Modify Static Data Okay?
    ... String-literal-created arrays are in principle read-only, ... 1989 ANSI standard) had no "const" keyword, ... The only way to reconcile these two desires was to make string ... arrays produced by string literals have type "const char ", ...
    (comp.lang.c)
  • Re: How do java programmers cope with java missing c++ const?
    ... to pass a const reference to a mutable object as can be done in c++. ... I also found the 'const' keyword in C++ to be very useful, ... It is a modifier used to change the characteristics to ... modified and must be initialized at the point of declaration. ...
    (comp.lang.java.programmer)
  • Re: Reintroducing fish, the friendly interactive shell
    ... If functions, indirect variable expansion, arrays, local ... their own line or after another keyword. ... As you mentioned in another post, zsh is much more clever in it's ... It is legal to have any number of newlines with no whitespace, ...
    (comp.unix.shell)
  • Re: Static Read-only array fields in C++
    ... If not using arrays, does the 'const' keyword actually result in the correct ... Also, any idea why this is an issue with managed arrays, and not other ... > Hi Mark, ...
    (microsoft.public.dotnet.languages.vc)

Quantcast