I have two functions:
void a(int * p);
int b();
Is it possible to pass the address of the return value of function b
to function a
something like this: a(&b())
?
A compound literal seems to do the trick (requires a C99 compiler):
int a()
{
return 5;
}
void b(int *a)
{
// do something with a
printf("%d\n", *a);
}
int main(void)
{
b(&(int){ a() });
}
Output is 5
.
Only by using a temporary variable:
int result = b();
a(&result);
EDIT: Apparently there's also a way to do this using a compound literal, described in another answer here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With