473,396 Members | 1,775 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,396 software developers and data experts.

address of return value

Hi,

How can I get the address of return value in function?

ex.

int function(int argument)
{
int *arg_address;
int *rtn_address;

arg_address = &argument;
rtn_address = ??;

Mar 31 '06 #1
11 3203
may be,you can do as following:

int ss(int i)
{
int *k = &i;
int *j = &i;
return (int)j; //this is a cast,becase j is a type of
int*
}

Mar 31 '06 #2
maybe,you can as following:
int ss(int i)
{
int *k = &i;
int *j = &i;
return (int)j; //this is a cast;

}

Mar 31 '06 #3
ig*********@gmail.com wrote:
Hi,

How can I get the address of return value in function?


It is not necessarily the case that the return value even has an
address. For sufficiently small types your compiler may choose to place
the return value in a register.

Alan
Mar 31 '06 #4
Hello,

ig*********@gmail.com wrote:
How can I get the address of return value in function?

Plain and simple answer, you can't. The location of the return value is
completely in the hands of the compiler, whether register or stack or
whatever. There are no syntactical means for influencing the return
value location or taking its address.

This would be helpfull to print return value automatically (when
object is destroyed).


I don't understand this, maybe you could provide a more complete
example, what you want to achieve, especially what it has to do with
destruction of an object.
Bernd

Mar 31 '06 #5
Getting an address of return value in function, why?

I think it's illegal, just silly.

The variable has been beyond its scope, but you want to use it by its'
pointer.

If i were you , I would never do that.

Mar 31 '06 #6

ig*********@gmail.com wrote:
Hi,

How can I get the address of return value in function?


Make the function take the address to store the return value into:

void f(int* result)
{
// here results is the address of the return value
*result = -1;
}

Mar 31 '06 #7
Well, it would be usefull for tracing. Destructor of object would print
return value automatically (when object goes out of scope - at the
return from function).

You can always do:
int f(int a)
{
int ret = 0;
int *ret_addr = &ret;
Apr 1 '06 #8
igor.....
do..u want to print..the address...of
variable...or....exact...locataion......of...retur n...value..location

Apr 1 '06 #9
I want to print return value automatically, without doing cout on every
return. This could be done if one has address of return variable or
address of temporary variable (above example), which is always set to
return value before actually returning. Then create an temporary
object, which prints this value at destruction.

Hope its clearer now. Should have give more info to start with... My
bad.

Regards,
Igor

Apr 2 '06 #10
I want to print return value automatically, without doing cout on every
return. This could be done if one has address of return variable or
address of temporary variable (above example), which is always set to
return value before actually returning. Then create an temporary
object, which prints this value at destruction.

Hope its clearer now. Should have give more info to start with... My
bad.

Regards,
Igor

Apr 2 '06 #11

ig*********@gmail.com wrote:
I want to print return value automatically, without doing cout on every
return. This could be done if one has address of return variable or
address of temporary variable (above example), which is always set to
return value before actually returning.


How about a suitable #define RETURN?

As an added bonus, you can make it print only in debug mode.

HTH,
Michiel Salters

Apr 3 '06 #12

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

Similar topics

3
by: Pushker Pradhan | last post by:
I have a function which should allocate memory, initialize it to some values and return the address of the initialized memory to the calling function. void getWaveletCoeffs(float *ld, float *hd,...
35
by: hasho | last post by:
Why is "call by address" faster than "call by value"?
27
by: Adam Warner | last post by:
Hi all, In the code snippet below I successfully determine the address of val1:* struct o val1=l_SYM_2B(&a).o; print_aesthetic(&val1); The structure o is heavyweight. I understand...
11
by: Brian Henry | last post by:
I have a domain cluster with AD running, and I want to lookup a users email address (exchange 2000 server is integrated with the AD system) so i can email the user based on their user name. does...
65
by: kyle.tk | last post by:
I am trying to write a function to convert an ipv4 address that is held in the string char *ip to its long value equivalent. Here is what I have right now, but I can't seem to get it to work. ...
25
by: Sourav | last post by:
Suppose I have a code like this, #include <stdio.h> int *p; void foo(int); int main(void){ foo(3); printf("%p %d\n",p,*p);
4
by: jdcrief | last post by:
Using Visual C++2005 Expression Edition Having trouble outputting the value referenced by the pointer and then outputing the address of the pointer for the char. Any ideas would be greatly...
11
by: !truth | last post by:
Hi, i feel confused about the following program, and it's works to get a pointer-member's address. #define NETDEV_ALIGN 32 #define NETDEV_ALIGN_CONST (NETDEV_ALIGN - 1) ...
4
by: kang jia | last post by:
hi i am doing mailinglist currently. the code in my first page is like this : : <html> <head> <link rel="stylesheet" type="text/css" href="gallery.css" /> <script language="JavaScript"> ...
4
by: karen.homersham | last post by:
Just working through Apress Pro ASP NET.2.0.E Commerce in C Sharp. I am having problems compiling the following: using System; using System.Collections.Generic; using System.Text; namespace...
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:
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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...

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.