473,569 Members | 2,791 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 #1
32 1461
Zytan wrote:
Are they possible? I am passing in a large array of Bytes, thus I
don't want to use ByVal.
When you pass an array by value, there's no copy of the array
contents, just of the array *variable*.

HTH.

Regards,

Branco,
Feb 1 '07 #2
Branco,

I had actually typed up a lengthy post asking about that, as well, and
Google Groups did something strange, and loaded a new page, erasing
the whole thing (one major flaw of web apps -- load a new page by
accident, and say goodbye to all your work), so I forgot about it, and
just asked the basic question.

I was going to ask if array variables are like C++ arrays (i.e. like
pointers), so that even if the 'pointer' is const, you can still
change what it points to (unless that is also const). All VB .NET
help files and tutorials never even touch upon these things. Very
annoying. It's like they think the programmer shouldn't be thinking
about these things...

Anyway... that leads to the question:

How can I pass in an array to a function/sub so that the entire array
is const and cannot be changed? Or should I be using C# instead for
such functionality?

Thanks for your reply,

Zytan

Feb 1 '07 #3
"Zytan" <zy**********@y ahoo.comschrieb :
How can I pass in an array to a function/sub so that the entire array
is const and cannot be changed? Or should I be using C# instead for
such functionality?
This cannot be done, not in VB and not in C#. You'd have to pass a copy of
the array or a proxy object to the function.

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

Feb 1 '07 #4
This is one of those:

Patient: "Doctor! It hurts when I do this."
Doctor: "Well don't do that!"

questions.

If you don't want the passed in array changed in your function, then don't
change it in your function!
"Zytan" <zy**********@y ahoo.comwrote in message
news:11******** **************@ v33g2000cwv.goo glegroups.com.. .
Branco,

I had actually typed up a lengthy post asking about that, as well, and
Google Groups did something strange, and loaded a new page, erasing
the whole thing (one major flaw of web apps -- load a new page by
accident, and say goodbye to all your work), so I forgot about it, and
just asked the basic question.

I was going to ask if array variables are like C++ arrays (i.e. like
pointers), so that even if the 'pointer' is const, you can still
change what it points to (unless that is also const). All VB .NET
help files and tutorials never even touch upon these things. Very
annoying. It's like they think the programmer shouldn't be thinking
about these things...

Anyway... that leads to the question:

How can I pass in an array to a function/sub so that the entire array
is const and cannot be changed? Or should I be using C# instead for
such functionality?

Thanks for your reply,

Zytan
Feb 1 '07 #5
Herfried,
This cannot be done, not in VB and not in C#. You'd have to pass a copy of
the array or a proxy object to the function.
I cannot *believe* this cannot be done. Wow... Ouch!

I know I can pass a copy (made with care) of the array, so that any
changes made within the function will not affect the original. But,
creating a copy of an array is a horrible thing to do when it needn't
be done... What terrible programming that would be, indeed. In my
case, I have an array of several MB in size.

Please elaborate on "proxy object".

Thanks for your reply,

Zytan

Feb 2 '07 #6
Stephany,
This is one of those:

Patient: "Doctor! It hurts when I do this."
Doctor: "Well don't do that!"

questions.

If you don't want the passed in array changed in your function, then don't
change it in your function!
No, no, no! This is very, very bad way of thinking about it. My
program doesn't change the array inside of the function. Really. I'm
a good programmer. Trust me. But, the point is... I don't trust
myself. The reason "const" exists is to prevent me from making
mistakes. Even the smartest of us make mistakes. The compiler helps
us avoid pitfalls with concepts like "const" and encapsulation. They
force good programming. That's why good programmers use them. I
can't even begin to explain how astonished I am at your reply...

I am further astonished that VB offers no way to protect programmers
from being stupid with passing in arrays. And that even C# doesn't
have this. I am just amazed... the fact that all VB programmers out
there in VB land are programming without this protection... and now
your reply makes more sense to me. Because it's the only solution, it
is the only way you CAN think about it. Amazing. (that is... unless
the proxy objects that Herfried mentioned are a solution...?)

Zytan

Feb 2 '07 #7
"Zytan" <zy**********@y ahoo.comschrieb :
>This cannot be done, not in VB and not in C#. You'd have to pass a copy
of
the array or a proxy object to the function.

Please elaborate on "proxy object".
\\\
Public Class ArrayProxy(Of T)
Private m_Array() As T

Public Sub New(ByVal Array() As T)
m_Array = Array
End Sub

Default Public ReadOnly Property Items(ByVal Index As Integer) As T
Get
Return m_Array(Index)
End Get
End Property
End Class
....
Dim Names() As String = ...
Foo(..., New ArrayProxy(Of String())(Names )), ...)
///

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

Feb 2 '07 #8
Yes you're absolutely right - the best of us do make mistakes.

That is why we have robust debugging and testing techniques.

Checking that some variable that shouldn't be modified hasn't been is the
most the most basic of those techniques.
"Zytan" <zy**********@y ahoo.comwrote in message
news:11******** *************@v 45g2000cwv.goog legroups.com...
Stephany,
>This is one of those:

Patient: "Doctor! It hurts when I do this."
Doctor: "Well don't do that!"

questions.

If you don't want the passed in array changed in your function, then
don't
change it in your function!

No, no, no! This is very, very bad way of thinking about it. My
program doesn't change the array inside of the function. Really. I'm
a good programmer. Trust me. But, the point is... I don't trust
myself. The reason "const" exists is to prevent me from making
mistakes. Even the smartest of us make mistakes. The compiler helps
us avoid pitfalls with concepts like "const" and encapsulation. They
force good programming. That's why good programmers use them. I
can't even begin to explain how astonished I am at your reply...

I am further astonished that VB offers no way to protect programmers
from being stupid with passing in arrays. And that even C# doesn't
have this. I am just amazed... the fact that all VB programmers out
there in VB land are programming without this protection... and now
your reply makes more sense to me. Because it's the only solution, it
is the only way you CAN think about it. Amazing. (that is... unless
the proxy objects that Herfried mentioned are a solution...?)

Zytan
Feb 2 '07 #9
Zytan,

This discussion is already from the first beta versions. In my idea are you
right, but this seems to be a hobby from the main architect from the Net
languages. (And unchangable now of course)

Cor

"Zytan" <zy**********@y ahoo.comschreef in bericht
news:11******** *************@v 45g2000cwv.goog legroups.com...
Stephany,
>This is one of those:

Patient: "Doctor! It hurts when I do this."
Doctor: "Well don't do that!"

questions.

If you don't want the passed in array changed in your function, then
don't
change it in your function!

No, no, no! This is very, very bad way of thinking about it. My
program doesn't change the array inside of the function. Really. I'm
a good programmer. Trust me. But, the point is... I don't trust
myself. The reason "const" exists is to prevent me from making
mistakes. Even the smartest of us make mistakes. The compiler helps
us avoid pitfalls with concepts like "const" and encapsulation. They
force good programming. That's why good programmers use them. I
can't even begin to explain how astonished I am at your reply...

I am further astonished that VB offers no way to protect programmers
from being stupid with passing in arrays. And that even C# doesn't
have this. I am just amazed... the fact that all VB programmers out
there in VB land are programming without this protection... and now
your reply makes more sense to me. Because it's the only solution, it
is the only way you CAN think about it. Amazing. (that is... unless
the proxy objects that Herfried mentioned are a solution...?)

Zytan

Feb 2 '07 #10

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

Similar topics

8
2456
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
1833
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
5266
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
2113
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*...
6
4893
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: -...
18
7317
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;...
13
27400
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
1630
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
1283
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
1774
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;...
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7605
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...
0
7917
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. ...
0
7962
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...
0
5217
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...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
933
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...

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.