473,699 Members | 2,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

constant references

Are they possible? I am passing in a large array of Bytes, thus I
don't want to use ByVal.

Zytan

Feb 1 '07
32 1477
On Feb 5, 7:36 am, "Zytan" <zytanlith...@y ahoo.comwrote:
Terry,
I know I am a little late in joining this discussion, but I was just reading
something in the documentation that may be of some help - not sure since I
have not tried it yet. New to the .Net Framework version 2 is the
"Array.AsReadOn ly" Generic Method that returns a read-only wrapper for the
specified array. So if you passed the original array (reference) byval, the
first line of code could be something like:
TheArray = Array.AsReadOnl y(TheArray) ' assuming the param was "TheArray"
Then it seems to me that the compiler should find and flag any attempts to
modify the array. And of course, the byval keeps the original reference from
being modified.

Thanks for the reply. Branco mentioned this earlier, and he claimed
that it still would only be caught at run time. I am not sure, I'd
have to test and see. But, this is better than nothing. And it's
better than proxy objects because it is specifically designed for
this, needing much less code. I'll give it a shot.

Thanks,

Zytan
Zytan,

ReadOnlyCollect ion is a proxy object because it can masquerade as an
IList like the original collection. The read-only check is performed
at runtime.

Brian
Feb 5 '07 #31
"Zytan" <zy**********@y ahoo.comschrieb :
>Before I wrote this I have looked at the calendar, and it is really 2007.

I thought that I was back in 1967 while I was reading your response.

Although I agree with you in concept is it now much to late start again a
discussion.

As the Arabs had than won the Arab-Isrealy war, than a lot of things
would
probably look different now, however you cannot change history (beside in
the schoolbooks of course).
[...]
Exactly what history must be changed in order for someone to improve
the compiler?
The 'const' attribute could be stored as an attribute in the parameters'
metadata, similar to how it is done for optional parameters and parameter
default values. That's not the problem.

The main problem I see is that the .NET Framework's class library currently
does not make use of such an attribute, but this would be crucial for its
overall success because most of the code makes calls to this class library.
In addition, all 3rd-party code would have to be reworked to make use of
const-correctness.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Feb 5 '07 #32
Herfried,
The 'const' attribute could be stored as an attribute in the parameters'
metadata, similar to how it is done for optional parameters and parameter
default values. That's not the problem.
Ok. That was my understanding.

The main problem I see is that the .NET Framework's class library currently
does not make use of such an attribute, but this would be crucial for its
overall success because most of the code makes calls to this class library.
In addition, all 3rd-party code would have to be reworked to make use of
const-correctness.
In my experience with C++, I've made use of the Win32 API which is
written in C, which doesn't use "const" (please correct me if I am
wrong). But, I still implemented "const" myself, for my own
libraries, and derived a benefit from them.

But, I do see your point. If almost ALL of the program's data is
passed to library calls, and this data disallows change, the library
functions will complain that they are expected data they are allowed
to modify.

However, consider a next generation .NET could implement "const" --
even only partially -- to the library, without any detriment to
existing code. A function that never changed its parameter data will
not care that it is no longer allowed to change it. Also, such
functions will continue to accept ANY type of data (readonly or not).
VB programmers could continue on with no knowledge of the changes...

No major internal architectures must change to make this happen, as we
seen with the VB6 to VB.NET switch. And, it can be introduced
incrementally. This is Good News.

Zytan

Feb 5 '07 #33

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

Similar topics

8
2461
by: Rickard Andersson | last post by:
What it the use of constant references in methods and functions? Is it a design issue or hwat? A reference that cannot be edited? huh? Why pass a reference then?
6
1838
by: amparikh | last post by:
I know this is something fundamental and I ought to have known it, but somehow this seems to be confusing me a lot. Fundamentally, rvalues and/or temporaries can be bound only to constant references going by the const guidelines. Taking that into consideration, how does one get a constant reference to a pointer. class A
11
5290
by: lovecreatesbeauty | last post by:
Hello experts, Is const_cast only applied to pointers or references? If I have a constant object, then how can I remove constant attribute from it? #include <vector> #include <string> using namespace std;
22
2130
by: Ben Finney | last post by:
Howdy all, I've recently packaged 'enum' in PyPI. In its description, I make the claim that it creates "immutable" enumeration objects, and that the enumeration values are "constant" values. This raises questions. Is there any difference between a Python immutable value, and a constant? I suppose "constant" also implies that the *name* binds
6
4903
by: cipher | last post by:
I have some constant values in my web service that my client application will require. Having to keep server side and client side definitions insync is tedious. I am trying to do something like this: public __value enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 }; However, the resulting wsdl omits the actual flag values: - <s:simpleType name="Colors">
18
7326
by: William | last post by:
I have the following javascript function that updates a scroll_list and sends the updated entry (with its index) to a server script ( i.e. http://mkmxg00/cgi/confirmUpload.pl ) for further processing: function saveText( scroll_list, t_area, listToBeUpdated ) { scroll_list.options.text = t_area.text; scroll_list.options.value= t_area.value; var req; var url = "http://mkmxg00/cgi/confirmUpload.pl";
13
27429
by: hn.ft.pris | last post by:
Hi: I have the following simple program: #include<iostream> using namespace std; int main(int argc, char* argv){ const double L = 1.234; const int T = static_cast<const int>(L); int arr;
13
1642
by: K. Jennings | last post by:
I have a function f with the following prototype: int f(void *). From my main() (or whatever) I can do things like int x = 123456 ; int y ; y = f(&x) ; which is fine. My question is, how can I pass the 123456 integer to f without using the intermediate x variable? Naively, what I would like to
12
1290
by: Bob Altman | last post by:
Hi all, I want to call a function that takes a void* argument and pass it the address of a constant. Is there a way to do this without explicitly defining the constant and then passing the address of the constant? In other words, what I *don't* want to do is this: const int myInt = 5; MyFunc(&myInt);
6
1780
by: Ruben | last post by:
re-reviewing the chapter in Lippan and Lajoie C++ Primer the have a section on references that I don't understand and just makes e shake my head believing that any behavior is possible with references and that they can never be understood. Maybe someone else can rephrase this so that I understand the defined behavior. cont int ival = 1024; //error: requires a const reference int *&pr_ref = &ival; //<<== this seems obvious as a...
0
8613
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9172
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8880
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7745
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.