modf() question

Discussion in 'C Programming' started by Christopher Benson-Manica, Apr 8, 2005.

  1. 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.
     
    Christopher Benson-Manica, Apr 8, 2005
    #1
    1. Advertising

  2. Christopher Benson-Manica

    Kevin Bracey Guest

    In message <d364vt$rej$>
    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?


    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/
     
    Kevin Bracey, Apr 8, 2005
    #2
    1. Advertising

  3. Christopher Benson-Manica

    Guillaume Guest

    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.
     
    Guillaume, Apr 8, 2005
    #3
  4. Kevin Bracey <> 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.
     
    Christopher Benson-Manica, Apr 8, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sean
    Replies:
    1
    Views:
    613
    Cowboy \(Gregory A. Beamer\)
    Oct 20, 2003
  2. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    Quick Question - Newby Question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Feb 14, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    682
    Iain Norman
    Feb 16, 2005
  3. =?Utf-8?B?YW5kcmV3MDA3?=

    question row filter (more of sql query question)

    =?Utf-8?B?YW5kcmV3MDA3?=, Oct 5, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    962
    Scott Allen
    Oct 6, 2005
  4. MarkN

    modf() - behavior

    MarkN, Aug 18, 2004, in forum: C Programming
    Replies:
    3
    Views:
    558
    -berlin.de
    Aug 18, 2004
  5. Replies:
    10
    Views:
    2,627
    Dik T. Winter
    Sep 30, 2008
Loading...

Share This Page