modf() question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christopher Benson-Manica

    modf() question

    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)cybers pace.org | don't, I need to know. Flames welcome.
  • Kevin Bracey

    #2
    Re: modf() question

    In message <d364vt$rej$1@c hessie.cirr.com >
    Christopher Benson-Manica <ataru@nospam.c yberspace.org> wrote:
    [color=blue]
    > 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?[/color]

    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/

    Comment

    • Guillaume

      #3
      Re: modf() question

      Christopher Benson-Manica wrote:[color=blue]
      > 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?[/color]

      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.

      Comment

      • Christopher Benson-Manica

        #4
        Re: modf() question

        Kevin Bracey <kevin.bracey@t ematic.com> spoke thus:
        [color=blue]
        > 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.[/color]

        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)cybers pace.org | don't, I need to know. Flames welcome.

        Comment

        Working...