473,406 Members | 2,371 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,406 software developers and data experts.

Address of a result?

I have a function that takes a pointer as an argument...
for example:

void myFunc(unsigned int * parameter)
how can I call myFunc with the result of a function without defining a
variable
to hold the parameter... ie.

main()
{
myFunc(&AnotherFunc()); // Wont work..
int p = AnotherFunc();
myFunc(&p); // Will work.
}

Will using a reference rather than a pointer help here?
Jul 22 '05 #1
8 1336
On Thu, 18 Dec 2003 18:03:47 GMT, "JustSomeGuy" <no**@nottelling.com> wrote:
I have a function that takes a pointer as an argument...
for example:

void myFunc(unsigned int * parameter)
how can I call myFunc with the result of a function without defining a
variable
to hold the parameter... ie.

main()
{
myFunc(&AnotherFunc()); // Wont work..
int p = AnotherFunc();
myFunc(&p); // Will work.
}

Will using a reference rather than a pointer help here?


That depends entirely on what myFunc does.

If you can use
void myFunc( usigned parameter )
that would be best.

If you can use
int* AnotherFunc()
that is second best.

Otherwise consider

void myFuncWrapper( int x )
{
myFunc( &x );
}
Jul 22 '05 #2
Hi,

"JustSomeGuy" <no**@nottelling.com> wrote in message
news:7_lEb.744528$6C4.70208@pd7tw1no...
I have a function that takes a pointer as an argument...
for example:

void myFunc(unsigned int * parameter)
how can I call myFunc with the result of a function without defining a
variable
to hold the parameter... ie. What does AnotherFunc returns. If it returns a pointer to something
allocated on the heap do this:

MyFunc( AnotherFunc() );

If it just returns the value of a local:

int AnotherFunc()
{
int I = 10;
return I;
}

Then you have to store the temporary:
Like this:

int P;
MyFunc( &( P = AnotherFunc() ) );

Or change the function myFunc:

void MyFunc( unsigned int parameter );

MyFunc( AnotherFunc() );

Since it doesn't make sence to change a temporary, why is it a pointer in
the first place?

main()
{
myFunc(&AnotherFunc()); // Wont work..
int p = AnotherFunc();
myFunc(&p); // Will work.
}

Will using a reference rather than a pointer help here?


No you have to store the returned temporary somewhere;
Regards Ron AF Greve
Jul 22 '05 #3

"Moonlit" <al******@jupiter.universe> wrote in message
news:3f*********************@news.xs4all.nl...
Hi,

"JustSomeGuy" <no**@nottelling.com> wrote in message
news:7_lEb.744528$6C4.70208@pd7tw1no...
I have a function that takes a pointer as an argument...
for example:

void myFunc(unsigned int * parameter)
how can I call myFunc with the result of a function without defining a
variable
to hold the parameter... ie. What does AnotherFunc returns. If it returns a pointer to something
allocated on the heap do this:

MyFunc( AnotherFunc() );

If it just returns the value of a local:

int AnotherFunc()
{
int I = 10;
return I;
}

Then you have to store the temporary:
Like this:

int P;
MyFunc( &( P = AnotherFunc() ) );

Or change the function myFunc:

void MyFunc( unsigned int parameter );

MyFunc( AnotherFunc() );

Since it doesn't make sence to change a temporary, why is it a pointer in
the first place?

Because it needs to change the contents of the value passed.



main()
{
myFunc(&AnotherFunc()); // Wont work..
int p = AnotherFunc();
myFunc(&p); // Will work.
}

Will using a reference rather than a pointer help here?


No you have to store the returned temporary somewhere;
Regards Ron AF Greve

Jul 22 '05 #4
Hi,

"JustSomeGuy" <no**@nottelling.com> wrote in message
news:YqmEb.750925$9l5.617540@pd7tw2no...

"Moonlit" <al******@jupiter.universe> wrote in message
news:3f*********************@news.xs4all.nl...
Hi,

"JustSomeGuy" <no**@nottelling.com> wrote in message
news:7_lEb.744528$6C4.70208@pd7tw1no...
I have a function that takes a pointer as an argument...
for example:

void myFunc(unsigned int * parameter)
how can I call myFunc with the result of a function without defining a
variable
to hold the parameter... ie. What does AnotherFunc returns. If it returns a pointer to something
allocated on the heap do this:

MyFunc( AnotherFunc() );

If it just returns the value of a local:

int AnotherFunc()
{
int I = 10;
return I;
}

Then you have to store the temporary:
Like this:

int P;
MyFunc( &( P = AnotherFunc() ) );

Or change the function myFunc:

void MyFunc( unsigned int parameter );

MyFunc( AnotherFunc() );

Since it doesn't make sence to change a temporary, why is it a pointer in the first place?

Because it needs to change the contents of the value passed.


The value will be gone at the end of the function call, so you have to store
it in a variable anyway.

Reagrds, Ron AF Greve


main()
{
myFunc(&AnotherFunc()); // Wont work..
int p = AnotherFunc();
myFunc(&p); // Will work.
}

Will using a reference rather than a pointer help here?


No you have to store the returned temporary somewhere;
Regards Ron AF Greve


Jul 22 '05 #5

"Moonlit" <al******@jupiter.universe> wrote in message
news:3f*********************@news.xs4all.nl...
Hi,

"JustSomeGuy" <no**@nottelling.com> wrote in message
news:YqmEb.750925$9l5.617540@pd7tw2no...

"Moonlit" <al******@jupiter.universe> wrote in message
news:3f*********************@news.xs4all.nl...
Hi,

"JustSomeGuy" <no**@nottelling.com> wrote in message
news:7_lEb.744528$6C4.70208@pd7tw1no...
> I have a function that takes a pointer as an argument...
> for example:
>
> void myFunc(unsigned int * parameter)
>
>
> how can I call myFunc with the result of a function without defining a > variable
> to hold the parameter... ie.
What does AnotherFunc returns. If it returns a pointer to something
allocated on the heap do this:

MyFunc( AnotherFunc() );

If it just returns the value of a local:

int AnotherFunc()
{
int I = 10;
return I;
}

Then you have to store the temporary:
Like this:

int P;
MyFunc( &( P = AnotherFunc() ) );

Or change the function myFunc:

void MyFunc( unsigned int parameter );

MyFunc( AnotherFunc() );

Since it doesn't make sence to change a temporary, why is it a pointer in the first place?
Because it needs to change the contents of the value passed.


The value will be gone at the end of the function call, so you have to

store it in a variable anyway.

Reagrds, Ron AF Greve


a variable I won't use...
I mean what is wrong with passing the address of the autovariable on the
return stack?



>
> main()
> {
> myFunc(&AnotherFunc()); // Wont work..
> int p = AnotherFunc();
> myFunc(&p); // Will work.
> }
>
> Will using a reference rather than a pointer help here?
>
>

No you have to store the returned temporary somewhere;
Regards Ron AF Greve



Jul 22 '05 #6

"JustSomeGuy" <no**@nottelling.com> wrote in message
news:%cnEb.745040$6C4.318035@pd7tw1no...

"Moonlit" <al******@jupiter.universe> wrote in message
news:3f*********************@news.xs4all.nl...
Hi,

"JustSomeGuy" <no**@nottelling.com> wrote in message
news:YqmEb.750925$9l5.617540@pd7tw2no...

"Moonlit" <al******@jupiter.universe> wrote in message
news:3f*********************@news.xs4all.nl...
> Hi,
>
> "JustSomeGuy" <no**@nottelling.com> wrote in message
> news:7_lEb.744528$6C4.70208@pd7tw1no...
> > I have a function that takes a pointer as an argument...
> > for example:
> >
> > void myFunc(unsigned int * parameter)
> >
> >
> > how can I call myFunc with the result of a function without
defining
a > > variable
> > to hold the parameter... ie.
> What does AnotherFunc returns. If it returns a pointer to something
> allocated on the heap do this:
>
> MyFunc( AnotherFunc() );
>
> If it just returns the value of a local:
>
> int AnotherFunc()
> {
> int I = 10;
> return I;
> }
>
> Then you have to store the temporary:
> Like this:
>
> int P;
> MyFunc( &( P = AnotherFunc() ) );
>
> Or change the function myFunc:
>
> void MyFunc( unsigned int parameter );
>
> MyFunc( AnotherFunc() );
>
> Since it doesn't make sence to change a temporary, why is it a
pointer
in
> the first place?
>
Because it needs to change the contents of the value passed.
The value will be gone at the end of the function call, so you have to

store
it in a variable anyway.

Reagrds, Ron AF Greve


a variable I won't use...
I mean what is wrong with passing the address of the autovariable on the
return stack?


How are you going to use the value that is the result from that operation
then? It is gone once the function returns.

What is wrong with using a variable? What exactly do you mean with
autovariable (automatic one i.e. a variable in your local routine or a
temporary one i.e. one that has disappeared at the end of your statement?

Regards, Ron AF Greve.

>
>
> >
> > main()
> > {
> > myFunc(&AnotherFunc()); // Wont work..
> > int p = AnotherFunc();
> > myFunc(&p); // Will work.
> > }
> >
> > Will using a reference rather than a pointer help here?
> >
> >
>
> No you have to store the returned temporary somewhere;
> Regards Ron AF Greve
>
>



Jul 22 '05 #7
JustSomeGuy wrote:
> > Since it doesn't make sence to change a temporary, why is it a
> > pointer in the first place?
> >
> Because it needs to change the contents of the value passed.
The value will be gone at the end of the function call, so you have
to store it in a variable anyway.

Reagrds, Ron AF Greve


a variable I won't use...


On one hand, your function must change the contents, on the other hand,
you don't want to do anything with the result of that change? That
doesn't make a lot of sense to me.
I mean what is wrong with passing the address of the autovariable on
the return stack?


The problem is that this address couldn't be used for anything.

Jul 22 '05 #8
pointer is the address of memory.
your function "AnotherFunc" return a value, the compile can't get the
address of it(coz the function will return a value by a register etc.)!
when you use p, then the compilke known the address is the address of
variable "p"
So...

"JustSomeGuy" <no**@nottelling.com> wrote in message
news:7_lEb.744528$6C4.70208@pd7tw1no...
I have a function that takes a pointer as an argument...
for example:

void myFunc(unsigned int * parameter)
how can I call myFunc with the result of a function without defining a
variable
to hold the parameter... ie.

main()
{
myFunc(&AnotherFunc()); // Wont work..
int p = AnotherFunc();
myFunc(&p); // Will work.
}

Will using a reference rather than a pointer help here?

Jul 22 '05 #9

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

Similar topics

10
by: Andrew DeFaria | last post by:
I was reading my O'Reilly JavaScript The Definitive Guide when I came across RegExp and thought I could tighten up my JavaScript code that checks for a valid email address. Why does the following...
8
by: YAN | last post by:
Hi, I want to get the mac address from a machine, which i have the IP address of that machine, how can i do that? I know how to get the mac address of the local machine from the following code: ...
5
by: Gidraz | last post by:
Hello, i can't figure out how to retrieve clients MAC address using C#.NET. I can get IP but not MAC. Thanks in advance. Gidraz
117
by: Steevo | last post by:
Any suggestions as to the best programs for cloaking email addresses? Many thanks -- Steevo
21
by: Stephen Biggs | last post by:
Given this code: void f(void){} int main(void){return (int)f+5;} Is there anything wrong with this in terms of the standards? Is this legal C code? One compiler I'm working with compiles this...
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...
33
by: baumann.Pan | last post by:
hi all, i want to get the address of buf, which defined as char buf = "abcde"; so can call strsep(address of buf, pointer to token);
3
by: steve | last post by:
anyone know how to get a network router's external ip address? any examples w/b great! tia, steve
8
by: =?big5?B?r0W84Q==?= | last post by:
Hi All C gurus: Below is a small program to print out the address of array and address of array variable: int main() { char array = "haha"; printf("array:%x\n", array); printf("&array:%x\n",...
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) ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.