modf() question

  • Thread starter Christopher Benson-Manica
  • Start date
C

Christopher Benson-Manica

Given that modf is prototyped as

double modf( double x, double *iptr );

is the behavior of the function well-defined if the address of x is
passed as the value of iptr?
 
K

Kevin Bracey

In message <[email protected]>
Christopher Benson-Manica said:
Given that modf is prototyped as

double modf( double x, double *iptr );

is the behavior of the function well-defined if the address of x is
passed as the value of iptr?

Absolutely. x is passed by value, so all that can happen is that the caller
passes a pointer to the argument it's passing. That won't point at the
copy of the parameter that the modf function sees, so there's no possible
aliasing problem.
 
G

Guillaume

Christopher said:
Given that modf is prototyped as

double modf( double x, double *iptr );

is the behavior of the function well-defined if the address of x is
passed as the value of iptr?

Technically, the question is fundamentally flawed because here, x is
a function argument and its address cannot be passed as another argument
of the same call. So this question is plain rubbish.

Now if that was meant to say "if the address of the variable passed
in the function call as the first argument", that's another story.
But anything could be passed as the first argument of this function,
including literals and expressions, so the parameter doesn't necessarily
even have an address (as defined by the operator '&').

Thus, this question doesn't make any sense per se. Ask your teacher to
write a better question, then work on it.
 
C

Christopher Benson-Manica

Kevin Bracey said:
Absolutely. x is passed by value, so all that can happen is that the caller
passes a pointer to the argument it's passing. That won't point at the
copy of the parameter that the modf function sees, so there's no possible
aliasing problem.

I should have been able to replicate that thought process - time for
more coffee, I suppose. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top