Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > modf() question

Reply
Thread Tools

modf() question

 
 
Christopher Benson-Manica
Guest
Posts: n/a
 
      04-08-2005
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?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
 
Reply With Quote
 
 
 
 
Kevin Bracey
Guest
Posts: n/a
 
      04-08-2005
In message <d364vt$rej$(E-Mail Removed)>
Christopher Benson-Manica <(E-Mail Removed)> wrote:

> 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.

--
Kevin Bracey, Principal Software Engineer
Tematic Ltd Tel: +44 (0) 1223 503464
182-190 Newmarket Road Fax: +44 (0) 1728 727430
Cambridge, CB5 8HE, United Kingdom WWW: http://www.tematic.com/
 
Reply With Quote
 
 
 
 
Guillaume
Guest
Posts: n/a
 
      04-08-2005
Christopher Benson-Manica wrote:
> 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.
 
Reply With Quote
 
Christopher Benson-Manica
Guest
Posts: n/a
 
      04-08-2005
Kevin Bracey <(E-Mail Removed)> spoke thus:

> 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.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question row filter (more of sql query question) =?Utf-8?B?YW5kcmV3MDA3?= ASP .Net 2 10-06-2005 01:07 PM
Quick Question - Newby Question =?Utf-8?B?UnlhbiBTbWl0aA==?= ASP .Net 4 02-16-2005 11:59 AM
Question on Transcender Question :-) eddiec MCSE 6 05-20-2004 06:59 AM
Question re: features of the 831 router (also a 924 question) Wayne Cisco 0 03-02-2004 07:57 PM
Syntax Question - Novice Question sean ASP .Net 1 10-20-2003 12:18 PM



Advertisments