Hi, I need your help because I don't understand very well this:
in C arguments are passed by-value. The function parameters get a copy
of the argument values.
But if I pass a pointer what really is happening? also a copy is passed
?
in C++ there is a pass-by-reference too... and in that case the
paramter can be considered as an
alias of the argument...
but now in C when we pass a pointer can we think of it as a
pass-by-address mechanism to manipulate
variables?
Thanks 14 2469
xdevel said:
Hi, I need your help because I don't understand very well this:
in C arguments are passed by-value.
Correct.
The function parameters get a copy of the argument values.
More precisely, arguments are *expressions*. The argument expressions are
evaluated, and those values are stored in the parameters to the function.
But if I pass a pointer what really is happening?
The pointer is evaluated, and that pointer's value is stored in the
parameter to the function, just the same as any other argument expression.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
xdevel wrote:
Hi, I need your help because I don't understand very well this:
in C arguments are passed by-value. The function parameters get a copy
of the argument values.
That's correct.
But if I pass a pointer what really is happening? also a copy is passed
?
A copy of the *pointer* is passed. The thing it's pointing to is *not*
copied.
in C++ there is a pass-by-reference too... and in that case the
paramter can be considered as an
alias of the argument...
While OT here, C++ references are really just a different way to refer
to pointers. It's just syntactic sugar that hides the "&" (at the
call) and "*()" (inside the function) operators from you.
but now in C when we pass a pointer can we think of it as a
pass-by-address mechanism to manipulate
variables?
If I'm interpreting your question correctly, yes. The passed pointer
will point to the original object, and the original object may be
accessed via that pointer. ro***********@y ahoo.com ha scritto:
While OT here, C++ references are really just a different way to refer
to pointers. It's just syntactic sugar that hides the "&" (at the
call) and "*()" (inside the function) operators from you.
ok but if I write a swap function with reference I can do this:
void swap(int &a, int &b)
{
int temp = 0;
int &tmp = temp;
tmp = a;
a = b;
b = tmp;
}
here I can swap the objects directly
and instead with pointer I can do this:
void swapP(int *a, int *b)
{
int tmp;
tmp = *a;
*a = *b;
*b = tmp;
}
I can't swap directly the pointers...
and so my question is why if pass-by-reference can be considerd as a
pass-by-pointer
is the code different?
what type of pointer is a reference?
Richard Heathfield ha scritto:
The pointer is evaluated, and that pointer's value is stored in the
parameter to the function, just the same as any other argument expression.
so in C exists only a pass-by-value mechanism in fact also if we pass a
pointer we are passing a copy of it while in C++ exists a pass-by-value
and a pass-by-reference mechanism
On Wed, 11 Oct 2006 07:18:17 +0000, Richard Heathfield wrote:
>xdevel said:
>But if I pass a pointer what really is happening?
The pointer is evaluated, and that pointer's value is stored in the parameter to the function, just the same as any other argument expression.
Sometimes called 'pass by address'.
Best regards,
Roland Pibinger
xdevel wrote:
ro***********@y ahoo.com ha scritto:
While OT here, C++ references are really just a different way to refer
to pointers. It's just syntactic sugar that hides the "&" (at the
call) and "*()" (inside the function) operators from you.
ok but if I write a swap function with reference I can do this:
void swap(int &a, int &b)
{
int temp = 0;
int &tmp = temp;
tmp = a;
a = b;
b = tmp;
}
here I can swap the objects directly
Why not just:
void swap(int &a, int &b)
{
int tmp;
tmp = a;
a = b;
b = tmp;
}
This at least matches the pointer based variant below.
and instead with pointer I can do this:
void swapP(int *a, int *b)
{
int tmp;
tmp = *a;
*a = *b;
*b = tmp;
}
I can't swap directly the pointers...
and so my question is why if pass-by-reference can be considerd as a
pass-by-pointer
is the code different?
what type of pointer is a reference?
Typically a reference parameter in a function call works internally
just like a pointer. I'd expect the generated code to generally be
identical. Using the swap example above, calling the reference version
with swap(x, y) would likely generate the identical code as calling the
pointer version with swap(&x, &y). Inside the reference version of
swap, the line a=b will essentially be transformed into *(A)=*(B) by
the compiler, where A and B are the internal pointers representing the
a and b parameters.
Of course the actual code generated by any particular compiler is
entirely up to the whim of the developers, and there's no reason they
cannot generate different code for the two cases.
References add no new functions to C++, but do allow a consistent way
to access member data and functions. That makes it possible to define
new types that have similar syntactic characteristics as the basic
types.
xdevel said:
>
Richard Heathfield ha scritto:
>The pointer is evaluated, and that pointer's value is stored in the parameter to the function, just the same as any other argument expression.
so in C exists only a pass-by-value mechanism
Correct.
in fact also if we pass a pointer we are passing a copy of it
More precisely, we are passing its value.
<off-topic stuff snipped>
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Roland Pibinger said:
On Wed, 11 Oct 2006 07:18:17 +0000, Richard Heathfield wrote:
>>xdevel said:
>>But if I pass a pointer what really is happening?
The pointer is evaluated, and that pointer's value is stored in the parameter to the function, just the same as any other argument expression.
Sometimes called 'pass by address'.
Why confuse the issue? The pointer's value is passed. In this respect,
expressions involving pointers and used as arguments are no different to
any other expressions that are used as arguments. There is no need to
invent a special terminology for pointers-as-arguments.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Roland Pibinger wrote:
On Wed, 11 Oct 2006 07:18:17 +0000, Richard Heathfield wrote:
>>xdevel said:
>>But if I pass a pointer what really is happening?
The pointer is evaluated, and that pointer's value is stored in the parameter to the function, just the same as any other argument expression.
Sometimes called 'pass by address'.
I've never heard pass-by-value of a pointer value be called
`pass by address`. I /have/ heard `pass [or call] by reference`
be called `pass by address`.
C's evaluation rules for arguments are the same as its evaluation
rules for expressions: it doesn't have special magic for pointer
expressions. (The nearest it has to a special pointer magic is that
array names evaluate to the address of their first element.)
--
Chris "Essen -8 and counting" Dollin
A rock is not a fact. A rock is a rock. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: uli2003wien |
last post by:
Dear group,
PASS (SQL-Server user group) is about to start founding a branch in
Vienna. I went to SQLCON and met some guys from the German PASS group
and decided to become a member of PASS, decided to look for other
individuals to take part in an Austrian branch of PASS based in Vienna,
so whoever is interested may take a look at
http://www.sqlpass.de/Default.aspx?tabid=191 in order to get to contact
me to get things going....
|
by: Tcs |
last post by:
I've been stumped on this for quite a while. I don't know if it's so simple
that I just can't see it, or it's really possible. (Obviously, I HOPE it IS
possible.)
I'm trying to get my queries to run from VB. My pass-thru query retrieves
data from our AS/400 that I use to build a local table (on my PC). My pass-thru
and local do in fact work together when I run them interactively. But I want,
no make that NEED, to run them from VB.
...
|
by: Robert |
last post by:
when using the following function to create a pass through query is there a
way to set the query property, "Returns Rows" to no. The default is yes.
Since we are planning to create the pass through with new parameters in the
where clause we need to set it each time. Thanx in advnance.
Function CreateSPT(SPTQueryName As String, strSQL As String)
Dim cat As ADOX.Catalog
Dim cmd As ADODB.Command
|
by: Zlatko Matić |
last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL
Server) and that we want to execute some parameterized query as a
pass.through query. How can we pass parameters to the server ?
Is it possible to use parameters in pass-through queries ?
An additional question: Is it possible to connect to a database on MySQL or
PostgreSQL using ADO ?
Is it possible to execute pass-through queries with parameters, using ADO...
|
by: Alex Nitulescu |
last post by:
Hi.
I have tried to pass two parameters, like this:
Response.Redirect(String.Format("NewPage.aspx?Username={0}, Pass={1}",
txtUserName.Text, txtPass.Text))
But if I pass Username="Alex" and Pass="AAA", I get Params("Username") =
"alex, Pass=AAA" and Params("Pass")="", which is not what I expected.
| |
by: Brett |
last post by:
I have several classes that create arrays of data and have certain
properties. Call them A thru D classes, which means there are four. I can
call certain methods in each class and get back an array of data. All four
classes are the same except for the number of elements in their arrays and
the data.
I have a MainClass (the form), which processes all of these arrays. The
MainClass makes use of third party objects to do this. There...
|
by: Marcelo |
last post by:
Any suggestion?
Thanks
Marcelo
|
by: ILCSP |
last post by:
Hello, I'm fairly new to the concept of running action pass through
queries (insert, update, etc.) from Access 2000. I have a SQL Server
2000 database and I'm using a Access 2K database as my front end.
I'm using a blank pass through query which gets the Transact-SQL part
inserted from a button in my form. After inserting the Transact-SQL
code into the pass through query, I 'open the recordset' to make the
query run.
However,...
|
by: marshmallowww |
last post by:
I have an Access 2000 mde application which uses ADO and pass through
queries to communicate with SQL Server 7, 2000 or 2005.
Some of my customers, especially those with SQL Server 2005, have had
pass-through queries fail due to intermittent connection failures.
I can easily restablish a connection for ADO.
My problem is with pass-through queries.
|
by: Remote_User |
last post by:
Hi,
Is there any way I can pass a file as a parameter? ( maybe read it
into a object) I am working on C# VS2005.
Thanks.
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |