473,796 Members | 2,544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

array of reference?

why can't we have array of references.
Dec 4 '07
31 3237
On Dec 7, 5:23 pm, James Kanze <james.ka...@gm ail.comwrote:
On Dec 7, 3:00 pm, "Alf P. Steinbach" <al...@start.no wrote:
* James Kanze:
On Dec 7, 4:06 am, "Alf P. Steinbach" <al...@start.no wrote:
>That said, using a hardware stack is the most common and today in
>practice the only implementation of the abstract machine's stack.
Sort of. In practice, except for Intel architecture (which is
notoriously poor in registers), I don't know of any case where
arguments are passed on the stack.
Recursion.

Even then, the *arguments* are passed in registers. (You can't
have the API of a function call depending on whether the
function is recursive or not.) Naturally, the function will
take whatever steps are necessary to avoid overwriting the value
(if it still needs it, of course) before placing the argument of
the next call in the register. On a Sparc, of course, nothing
is necessary; each function automatically gets a (partially) new
set of registers.
Some sort of storage with some size is essential to any none
resolvable parameter to a function (including references).But I
believe that in such case the size of storage cannot become less than
a complete pointer(segment , offset or whatever essential to uniquely
point to a specific memmory location).That is because generally it is
not predictable where the candidiate objects to be passed by ref are
to be stored.
That is what I had to write .
If I am wrong about the stack I do take it back.

regards,
FM.
Dec 8 '07 #21
On Dec 7, 7:23 pm, "Alf P. Steinbach" <al...@start.no wrote:
* James Kanze:


On Dec 7, 3:00 pm, "Alf P. Steinbach" <al...@start.no wrote:
* James Kanze:
>On Dec 7, 4:06 am, "Alf P. Steinbach" <al...@start.no wrote:
>>That said, using a hardware stack is the most common and today in
practice the only implementation of the abstract machine's stack.
>Sort of. In practice, except for Intel architecture (which is
notoriously poor in registers), I don't know of any case where
arguments are passed on the stack.
Recursion.
Even then, the *arguments* are passed in registers. (You can't
have the API of a function call depending on whether the
function is recursive or not.) Naturally, the function will
take whatever steps are necessary to avoid overwriting the value
(if it still needs it, of course) before placing the argument of
the next call in the register. On a Sparc, of course, nothing
is necessary; each function automatically gets a (partially) new
set of registers.

I fail to see how you can think that's anything but a hardware stack.
Maybe it is only my imagination ,but I can imagine a machine that just
does not have a push/pop pair and does not inc/dec a specific register
automatically and the call/ret code needs to handle it
manually ;something like this:

;//call:
move *SReg PC;//PC is the program counter
add SReg 1;
jump where;

;//ret:
sub SReg 1;
jump *SReg;

Regards,
FM.
Dec 8 '07 #22
On Dec 8, 8:16 pm, terminator <farid.mehr...@ gmail.comwrote:
On Dec 7, 7:23 pm, "Alf P. Steinbach" <al...@start.no wrote:
[...]
Even then, the *arguments* are passed in registers. (You can't
have the API of a function call depending on whether the
function is recursive or not.) Naturally, the function will
take whatever steps are necessary to avoid overwriting the value
(if it still needs it, of course) before placing the argument of
the next call in the register. On a Sparc, of course, nothing
is necessary; each function automatically gets a (partially) new
set of registers.
I fail to see how you can think that's anything but a hardware stack.
It's obviously a stack, but you don't pass arguments "on the
stack"; it all happens behind the scenes.

On the 8086, I also used a Pascal compiler which passed
arguments in a static area; saving it on the stack in case a
recursive call was detected. The arguments were never passed on
the stack, but the local context (including any arguments) were
copied onto the stack if necessary.
Maybe it is only my imagination, but I can imagine a machine that just
does not have a push/pop pair and does not inc/dec a specific register
automatically and the call/ret code needs to handle it
manually ;something like this:
;//call:
move *SReg PC;//PC is the program counter
add SReg 1;
jump where;
;//ret:
sub SReg 1;
jump *SReg;
It's not you imagination---I'd guess that this is the case for
most traditional hardware architectures. Even today, IBM
mainframes don't have a push and a pop, and don't save the
return address on the stack, but rather in a register.

Of the early machines, the Burroughs machines were stack based:
they didn't have registers, just top of stack. Other than such
special cases, however, I think that the PDP-11 was the first
machine which had a hardware stack (via auto-increment and
auto-decrement instructions).

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Dec 9 '07 #23
On Dec 8, 8:06 pm, terminator <farid.mehr...@ gmail.comwrote:
On Dec 7, 5:23 pm, James Kanze <james.ka...@gm ail.comwrote:
On Dec 7, 3:00 pm, "Alf P. Steinbach" <al...@start.no wrote:
* James Kanze:
On Dec 7, 4:06 am, "Alf P. Steinbach" <al...@start.no wrote:
That said, using a hardware stack is the most common and today in
practice the only implementation of the abstract machine's stack.
Sort of. In practice, except for Intel architecture (which is
notoriously poor in registers), I don't know of any case where
arguments are passed on the stack.
Recursion.
Even then, the *arguments* are passed in registers. (You can't
have the API of a function call depending on whether the
function is recursive or not.) Naturally, the function will
take whatever steps are necessary to avoid overwriting the value
(if it still needs it, of course) before placing the argument of
the next call in the register. On a Sparc, of course, nothing
is necessary; each function automatically gets a (partially) new
set of registers.
Some sort of storage with some size is essential to any none
resolvable parameter to a function (including references).
Some sort of storage is necessary any time there is state.
That's obvious. That doesn't mean that such state has size, in
the C++ sense---functions definitely require storage, but don't
have size either.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Dec 9 '07 #24
In article <4d2692d8-29f3-4246-bc88-
65**********@e4 g2000hsg.google groups.com>, ja*********@gma il.com says...

[ ... ]
Of the early machines, the Burroughs machines were stack based:
they didn't have registers, just top of stack. Other than such
special cases, however, I think that the PDP-11 was the first
machine which had a hardware stack (via auto-increment and
auto-decrement instructions).
http://www.ece.cmu.edu/~koopman/stac...ters/appa.html

--
Later,
Jerry.

The universe is a figment of its own imagination.
Dec 9 '07 #25
siddhu wrote:
why can't we have array of references.
Allowing arrays of references would introduce a number of rather convoluted
complications into language specification. I hope you know that arrays in C++
(inherited from C) are already rather strange objects possessing a number of
specific properties that make them stand out from other objects (like being
non-assignable, non-copy constructible, requiring dedicated initialization
syntax etc.) References are also tricky (non-objects as they are). Combining the
former and the latter together would lead to very complicated specification for
arrays. Apparently, the standardization committee decided to take the easy and
lazy way out and simply declare that you can't have arrays of references.

There was a number of technical reasons stated in this thread already (like
"references being non-objects" and "references having no size"), but in reality
no technical reason, of course, can be taken as a serious explanation. There's
no real technical difference in having references as members of arrays or having
references as members of any other aggregate type (members of a class). Yet it
is allowed to have class members of reference type in C++. This immediately
overthrows any technical reasoning against arrays of references, leaving us with
political explanations only.

Arrays, inherited from C, were seen as "broken beyond repair" in C++ from the
very beginning, so nobody wanted to spend too much time on creating an elaborate
specification for them. Any time any complications rose with any potential array
features, these feature were simply removed from the language. This is the real
answer to your question.

--
Best regards,
Andrey Tarasevich
Dec 10 '07 #26
On Dec 10, 7:48 am, Andrey Tarasevich <andreytarasev. ..@hotmail.com>
wrote:
siddhu wrote:
why can't we have array of references.

Allowing arrays of references would introduce a number of rather convoluted
complications into language specification. I hope you know that arrays in C++
(inherited from C) are already rather strange objects possessing a number of
specific properties that make them stand out from other objects (like being
non-assignable, non-copy constructible, requiring dedicated initialization
syntax etc.) References are also tricky (non-objects as they are). Combining the
former and the latter together would lead to very complicated specification for
arrays. Apparently, the standardization committee decided to take the easy and
lazy way out and simply declare that you can't have arrays of references.
I don't think arrays being non-copyable, non-assignable could be a
reason for not having array of references. After all, references are
non-copyable/non-assignable. That would have been supportive as that
is more in line to the properties of arrays. Initialization is a
problem, but it is the (almost?) same as having an array of const
objects. The standard does not prohibit array of const objects. For
example, this is ok:

struct A{
A(int){}
};

int main()
{
const A array[2] = {A(1), A(2)};
}

The same could have been possible for references as well. Which brings
us to an interesting point: arrays in C++ decay to pointers. So, when
passing this array to a function, you would actually be having a array
that decayed to a pointer whose value would be the pointer to the
first element in the array: array, or &array[0]. And as per the
standards a pointer to a reference is not allowed. I think, this is
because of the very same reason that has been pointed out earlier -
that references need not have size. So, I think, the answer that
arrays are not objects/arrays need not have size is the actual reason
why there can't be array of references.
Dec 10 '07 #27
Abhishek Padmanabh wrote:
>>why can't we have array of references.
Allowing arrays of references would introduce a number of rather convoluted
complication s into language specification. I hope you know that arrays in C++
(inherited from C) are already rather strange objects possessing a number of
specific properties that make them stand out from other objects (like being
non-assignable, non-copy constructible, requiring dedicated initialization
syntax etc.) References are also tricky (non-objects as they are). Combining the
former and the latter together would lead to very complicated specification for
arrays. Apparently, the standardization committee decided to take the easy and
lazy way out and simply declare that you can't have arrays of references.

I don't think arrays being non-copyable, non-assignable could be a
reason for not having array of references. After all, references are
non-copyable/non-assignable.
That's actually what I'm saying. There's no prohibitive technical reason for not
having arrays of references. Any technical problems could've been overcome with
more elaborate specification. The decision not to have arrays of references is
purely political.
The same could have been possible for references as well. Which brings
us to an interesting point: arrays in C++ decay to pointers.
...
And as per the
standards a pointer to a reference is not allowed.
It's nothing more that just another technical obstacle. For example, in C++ a
pointer to a POD-struct object converted by 'reinterpret_ca st' to type 'T*',
where 'T' is the type of the first field of that POD-struct, is guaranteed to
point to that first field. Does that mean that you can't have a reference as a
first member in a struct in C++? No it doesn't. And you can. It's just that the
struct with a reference member will no longer be a POD by definition.
I think, this is
because of the very same reason that has been pointed out earlier -
that references need not have size.
No. Any problems this could introduce could've been easily dealt with by
introducing extra restriction/exceptions into the language specification. Just
like the one above with pointers to struct members.
So, I think, the answer that
arrays are not objects/arrays need not have size is the actual reason
why there can't be array of references.
I don't understand what you are trying to say in that last sentence. Arrays are
objects in C++ and they do have size.

--
Best regards,
Andrey Tarasevich
Dec 10 '07 #28
On Dec 10, 8:36 pm, Andrey Tarasevich <andreytarasev. ..@hotmail.com>
wrote:
Abhishek Padmanabh wrote:
So, I think, the answer that
arrays are not objects/arrays need not have size is the actual reason
why there can't be array of references.

I don't understand what you are trying to say in that last sentence. Arrays are
objects in C++ and they do have size.
Aah.. that was a typo. I meant references.
Dec 10 '07 #29
Victor Bazarov wrote:
>...
Arrays are objects in C++ and they do have size.

But references don't. So, how would you define the size of an array
of refernces?
What's the problem? How do you "define" the size of a class that has a
member of reference type? The answer: normally the language simply says
that a class has _some_ size (which is what is returned by 'sizeof'),
but doesn't attempt to establish the relationship between the size of
the class and the size of its members. The result: the problem simply
does not exist.

Note, that with arrays the problem is not that they have sizes. The
problem with arrays is that the language goes on step further: it
postulates an additional relationship between the size of the array and
the size of the array element: sizeof(array) = sizeof(element) *
number_of_eleme nts. That's the problem. How can we deal with that?
Simple. For example, extend the concept of POD type to arrays, say that
arrays of references are not POD and that the aforementioned size
relationship applies only to POD arrays. For non-POD arrays the size is
unspecified. I.e. they have sizes, which can only be obtained from
'sizeof', but cannot be calculated in any other way. That's it.

Of course, then we'd have to deal with other complications, like what
these arrays should decay to (if at all) and so on. As I said before,
we'd end up with rather complicated specification for arrays. And all
these complications would have been caused by a feature of very limited use.
I don't believe it's totally impossible to solve some
"political" problems (as you put it) using some technical means, but
I don't think we should complain about it unless we're ourselves have
attempted it and succeeded. And even then there is no need to simply
complain. Just wrap your solution in a proposal and post to the
'comp.std.c++' newsgroup...
I don't really propose anything like that. The real root of the issue
here is not this particular mix of arrays and references. It's just
arrays themselves. They are broken. The problems with "arrays of
references" are just a logical consequence of C arrays' "brokenness ",
just like many other (non reference-related) problems stemming from the
same root. There's been lots of proposals to fix arrays, I'm sure. And
the committee already made a decision not to fix them. Coming up with a
proposal to enable "arrays of references" would be a futile attempt to
cure a symptom, instead of targeting the real problem, which in the end
would only try to make the arrays even more broken than they are already.

--
Best regards,
Andrey Tarasevich
Dec 10 '07 #30

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

Similar topics

5
2875
by: Nico | last post by:
Hello folks, I am currently storing a set of objects inside an array, $itemlist = array(); $itemlist = new item("myitem"); //... and I am looking to develop a search function, which returns a reference to the found item.
2
2017
by: Kaptain524 | last post by:
Hello, I am using PHP 5.0.4 with Apache 2, on WinXP Pro. This behavior appears to be fundamental however, and should not be affected by platform. It would seem that there is some kind of bug in the process that creates the reference when it is being assigned to an array element within itself. If it is already referenced, it just assigns the existing reference and avoids the problem.
12
55573
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are also removed) So far I have (val is value, ar is array, returns new array):
8
10234
by: Mike S. Nowostawsky | last post by:
I tried using the "toUpperCase()" property to change the value of an array entity to uppercase BUT it tells me that the property is invalid. It seems that an array is not considered an object when it is assigned a text literal?? HOW can I change the array value to upper case then? What other method exists for arrays? Ex: var GridArrayName1 = new Array(); GridArrayName1 = new Array ('test-value'); GridArrayName1 = GridArrayName1...
58
10186
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of code... TCHAR myArray; DoStuff(myArray);
10
10298
by: Fraser Ross | last post by:
I need to know the syntax for writing a reference of an array. I haven't seen it done often. I have a class with a member array and I want a member function to return an reference to it. Returning a pointer to the first element might do but I want to do what I've said. Fraser.
13
2533
by: Kevin | last post by:
Help! Why are none of these valid? var arrayName = new Array(); arrayName = new Array('alpha_val', 1); arrayName = ; I'm creating/writing the array on the server side from Perl, but I
32
6525
by: Joe Rattz | last post by:
Hmmm, I wrote the following code. I want an array of bools and I want to intialize them to false. bool bits = new bool; foreach(bool bit in bits) { bit = false; } The compiler complains on the "bit = false;" stating that bit is read-only.
16
1861
by: Frederick Gotham | last post by:
Inspired by page 219 of Nicolai M. Josuttis's book, I set out to write a class for an intrinsic array which would behave, to as far an extent as possible, like a container. Also though, I wanted no overhead whatsoever. The code I'm about to show below is not finished, it may contain the odd oversight, bug or error (but at a quick glance it seems OK). First of all though, I want to show you some macros I've written. The purpose of the...
14
20414
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is passed also. I understand that this way of passing the array is by value and if the prototype is declared as foo(int *), it is by reference in which case the value if modified in the function will get reflected in the main function as well. I dont...
0
9680
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9528
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
9052
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...
1
7548
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6788
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
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2926
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.