473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

'^' 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!
Nov 18 '05 #1
3 1460
Peteroid wrote:
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 ;
double^ x_ptr = x; // implicit boxing
y = ?x_ptr ; // y = double(7)
y = (double)x_ptr; // no implicit unboxing

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?


/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
Nov 18 '05 #2
Thanks, Carl!

[==P==]

"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:er**************@TK2MSFTNGP12.phx.gbl...
Peteroid wrote:
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 ;


double^ x_ptr = x; // implicit boxing

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


y = (double)x_ptr; // no implicit unboxing

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?


/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

Nov 18 '05 #3
"Peteroid" <pe************@msn.com> wrote
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 ;
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<double> 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.
y = ?x_ptr ; // y = double(7)
y =*x_ptr;
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?


double* __gc corresponds with interior_ptr<double>
__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
Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: xuatla | last post by:
I encountered "segmentation fault" and I checked my code, found the following problem: I want to reallocate memory for an array. I defined the following function: int reallocateMemory( double...
10
by: nospam | last post by:
Hello! I can pass a "pointer to a double" to a function that accepts double*, like this: int func(double* var) { *var=1.0; ... }
10
by: Robert Palma | last post by:
I'm having trouble figuring out how to pass a pointer to a double array (1 dimensional) to a C function. Declaring array as: double xx; Declaring func. int process( double *input ) Calling...
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
21
by: Roman Werpachowski | last post by:
I can't understand this: double * x = new double; const double * p = x; delete p; works. Why am I allowed to delete a const pointer? On the same note: why am I allowed to do this: class...
42
by: xdevel | last post by:
Hi, if I have: int a=100, b = 200, c = 300; int *a = {&a, &b, &c}; than say that: int **b is equal to int *a is correct????
1
by: urkel | last post by:
Hi everyone, I critically need help to solve this problem related to pointer in C++ Basically, I have a C/C++ program "retardselfenerg" calling a Fortran 90 subroutine "surfGF4.f90". i am so...
34
by: sumedh..... | last post by:
double * X size of X->?? size of X->?? double (*X) size of X->?? size of X->??
17
by: Ivan K. | last post by:
I am looking at some legacy code, which begins by allocating a double matrix with the dmatrix() function from NRC as follows: double **A, **augin, **augout, **aa; A = dmatrix(1,...
14
by: Szabolcs Borsanyi | last post by:
Deal all, The type typedef double ***tmp_tensor3; is meant to represent a three-dimensional array. For some reasons the standard array-of-array-of-array will not work in my case. Can I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.