473,394 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

References in C++

can anybody explain me how exactly C++ lang implements references.I read it
from some where that it is nothing but const pointer internally but few of
my seniors told me its not that than what is it how its implemented....plz
help me
thanks in advance .

Jul 23 '05 #1
8 1230
apoorv wrote:
can anybody explain me how exactly C++ lang implements references.I read
it from some where that it is nothing but const pointer internally but few
of my seniors told me its not that than what is it how its
implemented....plz help me


Typically, references are indeed internally implemented the same way as
pointers. I've never heard of any other way of implementing them, but that
doesn't mean much.

Jul 23 '05 #2
apoorv wrote:
can anybody explain me how exactly C++ lang implements references.

This is upon the implementation to decide.

I read it
from some where that it is nothing but const pointer internally but few of
my seniors told me its not that than what is it how its implemented....plz

It may be implemented in such a way, however in many cases a reference
may be optimised out of the compiler, so as a separate "reference
object" does not exist.

This is why references have no size nor a memory address of their own in
ISO C++.


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #3
Ioannis Vranos wrote:
It may be implemented in such a way, however in many cases a reference
may be optimised out
by
the compiler, so as a separate "reference object" does not exist.

This is why references have no size nor a memory address of their own
in ISO C++.



--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #4
Ioannis Vranos wrote:
I read it
from some where that it is nothing but const pointer internally but few
of my seniors told me its not that than what is it how its
implemented....plz

It may be implemented in such a way, however in many cases a reference
may be optimised out of the compiler, so as a separate "reference
object" does not exist.


However, there is no reason why in such situations a pointer couldn't be
optimized away, too.
This is why references have no size nor a memory address of their own in
ISO C++.


However, they still might take up detectable storage, e.g. if used as a
class member.

Jul 23 '05 #5

Rolf Magnus wrote:
Ioannis Vranos wrote:
I read it
from some where that it is nothing but const pointer internally but few of my seniors told me its not that than what is it how its
implemented....plz

It may be implemented in such a way, however in many cases a reference may be optimised out of the compiler, so as a separate "reference
object" does not exist.


However, there is no reason why in such situations a pointer couldn't

be optimized away, too.


Actually, there is: pointers, unlike references, are PODs and can
be memcpy'd. That restricts the ability to optimize them away - it's
much harder to detect all the reads of and writes to a pointer.

HTH,
Michiel Salters

Jul 23 '05 #6
"apoorv" <ar**********@nospam.quark.com> wrote in message
news:e8******************************@localhost.ta lkaboutprogramming.com...
can anybody explain me how exactly C++ lang implements references.
No, nobody can, because the language does not define how
they're implemented, only how they behave. Their specific
implementation is up to the compiler.
I read it
from some where that it is nothing but const pointer internally
Many compilers implement references as 'hidden' pointers,
but there's no requirement that any do.
but few of
my seniors told me its not that
They should have told you that it might be that, but might not.
than what is it how its implemented


It depends upon the compiler. Why do you need to know?

-Mike
Jul 23 '05 #7

apoorv wrote:
can anybody explain me how exactly C++ lang implements references.


You're making a fundamental mistake. The language doesn't implement
anything, it only provides a specification for behavior.
Implementations (duh) implement things.


Brian

Jul 23 '05 #8
apoorv wrote:
Can anybody explain me how exactly C++ language implements references.
The C++ computer programming language does *not* implement anything.
Compiler developers "implement" the language.
I read it from some where that
it is nothing but const pointer internally
A reference is just another name (a synonym) for an object.

int i = 13; // an object of type int named i
int* p = &i; // a pointer to an object of type int
int& k = *p; // another name for i

The pointer p is an object but the reference k is not.
k is just another name for i (or *p in this case).
Pass by reference:

void f(int& k);

and pass by reference through a pointer:

void g(int* p);

are implemented exactly the same way -
the compiler generates code to pass the address of k (or *p)
[by value] to the function.
but few of my seniors told me [that]
it's not that than what is it how it's implemented.


I can't parse that.
Jul 23 '05 #9

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

Similar topics

17
by: Tom | last post by:
The motivation for references seems clear: stop people from using nasty pointers when all they really want is a reference to an object. But C++ references are so inadequate that I'm still using...
22
by: xmp333 | last post by:
Hi All, I am trying to hide my JavaScript source. The method I chose was to keep all the important source in a password protected folder, and then use a SRC="folder/script.js" to include it...
33
by: JKop | last post by:
I understand variables/objects and pointer variables perfectly: int X = 5; int* pX = &X; *pX = 4; int** ppX = &pX:
2
by: S. van Beek | last post by:
Dear reader, For removing a reference in the VBA reference form I receive from Doug Steele the following code: ........... References.Remove refCurr
11
by: codebloatation | last post by:
I know how to use references but i DO not get WHY they exist other than to add to the language. Are they actually needed for anything?
14
by: el_sid | last post by:
Our developers have experienced a problem with updating Web References in Visual Studio.NET 2003. Normally, when a web service class (.asmx) is created, updating the Web Reference will...
30
by: jeremygetsmail | last post by:
I've got an adp (Metrix.adp) with a reference to another adp (InteractSQL.adp). InteractSQL sits on a server, and is refered to by all of the clients (Metrix), which sit on the client machines...
3
by: DonJefe | last post by:
Does anyone have experience using project->project references in large solutions? What are the plus/minuses that you have found? Currently, we are using the binary assembly references for our...
9
by: igor.kulkin | last post by:
References is a relatively basic feature of C++ language. It might be a good thing to think of references as aliases to the variables. However it's good to think of references this way when you...
3
by: CenturionX | last post by:
Hello everybody: I'd like to know what references in my vba code are used or not. I work in a code made by another person previously, i founded to many references and i believe that someones...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
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,...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.