'^' pointer to a double

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peteroid

    '^' pointer to a double

    I'm using VS C++.NET 2005 Express in /clr. How do I create, and then use, a
    '^' pointer to a 'double'? That is, assuming its possible, please fill in
    the question marks below (there are two of them):

    double x = double(7) ;
    double y ;

    double^ x_ptr = ?x ;

    y = ?x_ptr ; // y = double(7)

    I'd know how to do this if 'x' and 'y' were an instances of a ref class, but
    not when they are something like a double, int, long, etc. If I can remove
    my current dependency on code of the form 'double *' (I need pointers to
    doubles) I think I can go from /clr to /clr pure (or /clr safe, not sure
    what the difference is between these last two, or which is 'stronger'). What
    are the advantages of going 'purer' than /clr?

    Thanks in advance for responses!


  • Carl Daniel [VC++ MVP]

    #2
    Re: '^' pointer to a double

    Peteroid wrote:[color=blue]
    > I'm using VS C++.NET 2005 Express in /clr. How do I create, and then
    > use, a '^' pointer to a 'double'? That is, assuming its possible,
    > please fill in the question marks below (there are two of them):
    >
    > double x = double(7) ;
    > double y ;
    >
    > double^ x_ptr = ?x ;[/color]

    double^ x_ptr = x; // implicit boxing[color=blue]
    >
    > y = ?x_ptr ; // y = double(7)[/color]

    y = (double)x_ptr; // no implicit unboxing
    [color=blue]
    >
    > I'd know how to do this if 'x' and 'y' were an instances of a ref
    > class, but not when they are something like a double, int, long, etc.
    > If I can remove my current dependency on code of the form 'double *'
    > (I need pointers to doubles) I think I can go from /clr to /clr pure
    > (or /clr safe, not sure what the difference is between these last
    > two, or which is 'stronger'). What are the advantages of going
    > 'purer' than /clr?[/color]

    /clr:safe is "stronger" than /clr:pure.

    /clr - may generate mixed-mode code
    /clr:pure - generates only IL
    /clr:safe - generates only verifiable IL

    -cd


    Comment

    • Peter Oliphant

      #3
      Re: '^' pointer to a double

      Thanks, Carl!

      [==P==]

      "Carl Daniel [VC++ MVP]" <cpdaniel_remov e_this_and_nosp am@mvps.org.nos pam>
      wrote in message news:erX3ti$6FH A.3684@TK2MSFTN GP12.phx.gbl...[color=blue]
      > Peteroid wrote:[color=green]
      >> I'm using VS C++.NET 2005 Express in /clr. How do I create, and then
      >> use, a '^' pointer to a 'double'? That is, assuming its possible,
      >> please fill in the question marks below (there are two of them):
      >>
      >> double x = double(7) ;
      >> double y ;
      >>
      >> double^ x_ptr = ?x ;[/color]
      >
      > double^ x_ptr = x; // implicit boxing[color=green]
      >>
      >> y = ?x_ptr ; // y = double(7)[/color]
      >
      > y = (double)x_ptr; // no implicit unboxing
      >[color=green]
      >>
      >> I'd know how to do this if 'x' and 'y' were an instances of a ref
      >> class, but not when they are something like a double, int, long, etc.
      >> If I can remove my current dependency on code of the form 'double *'
      >> (I need pointers to doubles) I think I can go from /clr to /clr pure
      >> (or /clr safe, not sure what the difference is between these last
      >> two, or which is 'stronger'). What are the advantages of going
      >> 'purer' than /clr?[/color]
      >
      > /clr:safe is "stronger" than /clr:pure.
      >
      > /clr - may generate mixed-mode code
      > /clr:pure - generates only IL
      > /clr:safe - generates only verifiable IL
      >
      > -cd
      >
      >[/color]


      Comment

      • Holger Grund

        #4
        Re: '^' pointer to a double

        "Peteroid" <peter_oliphant @msn.com> wrote
        [color=blue]
        > I'm using VS C++.NET 2005 Express in /clr. How do I create, and then use,
        > a '^' pointer to a 'double'? That is, assuming its possible, please fill
        > in the question marks below (there are two of them):
        >
        > double x = double(7) ;
        > double y ;
        >
        > double^ x_ptr = ?x ;
        >[/color]
        Note that double^ is a reference type (it's what e.g. C# treats as
        an object)
        double x = 7.;
        object o = (object)x; // boxing

        If you want a managed pointer (this is what ref/out in C# yield, or
        a float64& in CLR speak) you can use

        // has C++ reference semantics x_ref = 1 assigns to x
        double% x_ref = x;

        // managed pointer, has C++ pointer semantics
        interior_ptr<do uble> x_ptr = &x;

        There is a performance overhead associated with boxing (essentially
        it creates a full object - supporting several interfaces, strong object
        identity etc. - around the data value)

        Why the language designers chose to deviate from the semantics for
        reference types is beyond me.
        [color=blue]
        > y = ?x_ptr ; // y = double(7)
        >[/color]
        y =*x_ptr;
        [color=blue]
        > I'd know how to do this if 'x' and 'y' were an instances of a ref class,
        > but not when they are something like a double, int, long, etc. If I can
        > remove my current dependency on code of the form 'double *' (I need
        > pointers to doubles) I think I can go from /clr to /clr pure (or /clr
        > safe, not sure what the difference is between these last two, or which is
        > 'stronger'). What are the advantages of going 'purer' than /clr?[/color]

        double* __gc corresponds with interior_ptr<do uble>
        __box double* corresponds with double^
        __box(x) is used to box a value. This conversion is implicit with C++/CLI,
        but you probably want to be explicit and use a box(_cast) helper function
        template.

        You should be able to use /clr:pure with almost everything including
        native pointers (double* in C++/CLI). /clr:pure can operate on "unmanaged
        data" (i.e. memory that is not managed by the CLR execution engine).
        MSIL can describe such operations. There is almost nothing you get by
        going from /clr to /clr:pure except maybe making things much more simple
        for a certain type of static analysis tools.

        /clr:safe is much more strict and won't let you do anything with native
        pointers
        (at least almost). But many things involving managed pointers are not
        verifiable
        as well. Essentially, they're only useful for parameter passing (e.g. ref
        and out
        in C#). Managed pointers can only be used in contexts with automatic storage
        duration.

        hth
        -hg


        Comment

        Working...