473,796 Members | 2,583 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 3236
On Dec 6, 6:47 pm, Joe Greer <jgr...@doublet ake.comwrote:
terminator <farid.mehr...@ gmail.comwrote in news:b2d73c27-cfd5-42ee-ae2d-
2b5790802...@s3 6g2000prg.googl egroups.com:
On Dec 5, 12:32 am, "Alf P. Steinbach" <al...@start.no wrote:
* siddhu:
why can't we have array of references.
A reference is not an object, it has no size.
it has a size usually equal to that of a pointer in case of usage an
argument to a none inlined function.

No, references don't even have to have a physical representation.
Analogous to typedef, a reference only introduces a new name for an object.
It turns out that usually memory for an address is allocated for reference
parameters and reference object members, but it would be a pretty poor
compiler that allocated anything at all for a local reference.

joe
I said in case of usage as **an argument to a none inlined function**.
Dec 6 '07 #11
On Dec 6, 12:41 am, "Alf P. Steinbach" <al...@start.no wrote:
* terminator:
On Dec 5, 12:32 am, "Alf P. Steinbach" <al...@start.no wrote:
* siddhu:
>why can't we have array of references.
A reference is not an object, it has no size.
it has a size usually equal to that of a pointer in case of usage an
argument to a none inlined function.

Sorry, that's incorrect. Or not even wrong. If you want to make an
argument, cough up chapter and verse from the standard.
I do not get it:

void f(int& iref);

can you explain how 'iref ' is passed to 'f' if it is not inlined?
The simplest way is to implement it as a pointer ,so stack register
will be decreased sizeof(int*) for passing 'iref'.

regards,
FM.
Dec 6 '07 #12
On Dec 6, 12:35 am, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
terminator wrote:
On Dec 5, 12:32 am, "Alf P. Steinbach" <al...@start.no wrote:
* siddhu:
>why can't we have array of references.
A reference is not an object, it has no size.
it has a size usually equal to that of a pointer in case of usage an
argument to a none inlined function.

And when the size isn't equal to that of a pointer, what is it?
Nothing,A pseudo C++ instruction, not even some gaseus.when not an
argument to out of line functions it is resolved at compile time.

regards,
FM.
Dec 6 '07 #13
terminator <fa***********@ gmail.comwrote in
news:e7******** *************** ***********@e10 g2000prf.google groups.com:
On Dec 6, 6:47 pm, Joe Greer <jgr...@doublet ake.comwrote:
>terminator <farid.mehr...@ gmail.comwrote in
news:b2d73c2 7-cfd5-42ee-ae2d-
2b5790802...@s 36g2000prg.goog legroups.com:
On Dec 5, 12:32 am, "Alf P. Steinbach" <al...@start.no wrote:
* siddhu:
why can't we have array of references.
>A reference is not an object, it has no size.
it has a size usually equal to that of a pointer in case of usage
an argument to a none inlined function.

No, references don't even have to have a physical representation.
Analogous to typedef, a reference only introduces a new name for an
object. It turns out that usually memory for an address is allocated
for reference parameters and reference object members, but it would
be a pretty poor compiler that allocated anything at all for a local
reference.

joe

I said in case of usage as **an argument to a none inlined function**.
Sadly (or is it gladly? Depends upon the topic and POV.) you don't
really have any control over that. Some of today's modern compilers can
inline in the linker stage. Some classes with reference member
variables can also be unrolled and inlined during compilation.
Therefore, it's hard to make any flat statement about the storage of
references other than they don't require any.

joe
Dec 6 '07 #14
Alf P. Steinbach wrote:
>it has a size usually equal to that of a pointer in case of usage an
argument to a none inlined function.

Sorry, that's incorrect. Or not even wrong. If you want to make an
argument, cough up chapter and verse from the standard.
He said "usually", which I understand to mean "in practice with
current compilers and architectures".
Dec 7 '07 #15
On Dec 6, 5:52 pm, terminator <farid.mehr...@ gmail.comwrote:
On Dec 6, 12:41 am, "Alf P. Steinbach" <al...@start.no wrote:
* terminator:
On Dec 5, 12:32 am, "Alf P. Steinbach" <al...@start.no wrote:
>* siddhu:
>>why can't we have array of references.
>A reference is not an object, it has no size.
it has a size usually equal to that of a pointer in case
of usage an argument to a none inlined function.
Sorry, that's incorrect. Or not even wrong. If you want to
make an argument, cough up chapter and verse from the
standard.
I do not get it:
void f(int& iref);
can you explain how 'iref ' is passed to 'f' if it is not
inlined? The simplest way is to implement it as a pointer ,so
stack register will be decreased sizeof(int*) for passing
'iref'.
First, inlining or not is irrelevant. The standard specifically
states that inlining has no effect on a function, so it can't
possibly the size of an argument to the function can't possibly
depend on that. Second, how the compiler passes arguments with
reference type is it's business, not mine. My compiler
certainly doesn't pass them on the stack; it puts them in a
register. A 64 bit register, even when I'm compiling in 32 bit
mode (where pointers are 32 bits). And on my compiler, the
actual memory space used by a reference in a structure will
depend on what is in front of and behind the reference. (The
same is true of pointers, of course.)

What is relevant is that the compiler says that sizeof( char& )
== 1, and sizeof( T& ) == sizeof( T ), regardless of the size of
a pointer. A reference doesn't have size. At least not of its
own. A reference is an other name for a variable or a value,
and its "size" is the size of whatever it names.

--
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 7 '07 #16
On Dec 7, 4:06 am, "Alf P. Steinbach" <al...@start.no wrote:
* terminator:
I do not get it:
void f(int& iref);
can you explain how 'iref ' is passed to 'f' if it is not inlined?
The simplest way is to implement it as a pointer ,so stack register
will be decreased sizeof(int*) for passing 'iref'.
First, note that there may not be a stack register.
The C++ abstract machine implicitly defines a logical stack, a
LIFO queue, for automatic variables and function arguments,
but that does not mean that it depends on a stack register at
the hardware level or hardware support for a call stack.
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. They're passed in registers.
On a modern Sun Sparc (v9 or later), those registers are always
64 bits: 8 bytes. So a reference will be passed in 8 bytes. As
will a char, a short, an int, a long or a long long, all
pointers (even in 32 bit mode, where a pointer is normally only
4 bytes), and all enums. (None of which has anything to do with
the size of the type in the C++ sense, but I'm sure you know
that already.)

Also, in addition to a stack register, the Sparc has a register
stack. When you call a function, it is shifted down 192 bytes,
regardless of the number and types of the arguments. Does this
mean that if I call a function with one reference argument, the
size of the reference is 192, but if I call it with 2, the size
is 96?

[...]
Common to all these cases is that because references do not
have size at the abstract machine level, and are not objects
at the abstract machine level, the compiler is free to
optimize or do anything.
Note that unless you actually output the value of a pointer,
that's fairly true for pointers as well. All the actual machine
has to do is ensure that the observable behavior is the same as
one possible instantiation of the abstract machine.
All the compiler needs to do -- barring use of
compiler-specific language extensions -- is to make sure the
requirements of the abstract machine are fulfilled, treating
the reference as an alias.
Just to add to the confusion: according to the standard,
references do have size, since sizeof( T& ) is a perfectly
legal, well defined instruction. And a reference to a pointer
does have the size of a pointer. Just as a reference to an int
has the size of an int, and a reference to a double has the size
of a double. And on my machine, a reference to an int[1000000]
has a size of 8000000---good thing pointers aren't that big.

Also, C++ guarantees that a[i] is the same as *(a + i), and that
if a has type T[] (or T*), (char*)a + sizeof(T)*i == &a[i]. Now
explain what that last expression does where T is a reference.
(I think new T[n] would also be a bit of a problem if T could
have a reference type. Or even simply new T---which guarantees
that operator new( sizeof( T ) ) will be called.)

--
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 7 '07 #17
On Dec 6, 5:48 pm, terminator <farid.mehr...@ gmail.comwrote:
On Dec 6, 6:47 pm, Joe Greer <jgr...@doublet ake.comwrote:
terminator <farid.mehr...@ gmail.comwrote in news:b2d73c27-cfd5-42ee-ae2d-
2b5790802...@s3 6g2000prg.googl egroups.com:
On Dec 5, 12:32 am, "Alf P. Steinbach" <al...@start.no wrote:
>* siddhu:
why can't we have array of references.
>A reference is not an object, it has no size.
it has a size usually equal to that of a pointer in case of usage an
argument to a none inlined function.
No, references don't even have to have a physical
representation. Analogous to typedef, a reference only
introduces a new name for an object. It turns out that
usually memory for an address is allocated for reference
parameters and reference object members, but it would be a
pretty poor compiler that allocated anything at all for a
local reference.
I said in case of usage as **an argument to a none inlined
function**.
Which is a pretty meaningless statement. With Sun CC, on a
Sparc, when I call something like f(int&), the compiler
decrements the stack pointer by 192. What does this tell us
about the size of a reference, or the size of the return value,
or anything else?

--
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 7 '07 #18
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.

--
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 7 '07 #19
On Dec 6, 6:47 pm, Joe Greer <jgr...@doublet ake.comwrote:
terminator <farid.mehr...@ gmail.comwrote in news:b2d73c27-cfd5-42ee-ae2d-
2b5790802...@s3 6g2000prg.googl egroups.com:
On Dec 5, 12:32 am, "Alf P. Steinbach" <al...@start.no wrote:
* siddhu:
why can't we have array of references.
A reference is not an object, it has no size.
it has a size usually equal to that of a pointer in case of usage an
argument to a none inlined function.

No, references don't even have to have a physical representation.
Analogous to typedef, a reference only introduces a new name for an object.
It turns out that usually memory for an address is allocated for reference
parameters and reference object members, but it would be a pretty poor
compiler that allocated anything at all for a local reference.

joe
that is just what I wrote.maybe I am so bad a composer.

regards,
FM.
Dec 7 '07 #20

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
10183
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
1860
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
10455
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
10228
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...
1
7547
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
5441
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4116
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
2925
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.