473,803 Members | 3,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

'^' 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 1477
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.nos pam>
wrote in message news:er******** ******@TK2MSFTN GP12.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<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.
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<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
Nov 18 '05 #4

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

Similar topics

13
2504
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 *array, int newsize ) { if (array) delete array;
10
9160
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
8663
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 func. as one of the following:
204
13141
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 = {0,1,2,4,9};
21
18626
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 probna {
42
5350
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
23440
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 doubtful if my definitions of pointer variables and their use in calling function are correct. #include<bla bla bla......h> #include<bla bla bla.h> double surfGF4_(double*, double*, double*, double*, double*, double*, double*, double*, double*); ...
34
1916
by: sumedh..... | last post by:
double * X size of X->?? size of X->?? double (*X) size of X->?? size of X->??
17
5262
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, MAXNSTU+1, 1, MAXCOV+MAXCOVLOC+3); aa = dmatrix(1, MAXNSTU+1, 1, MAXCOV+MAXCOVLOC+3); augin = dmatrix(1, MAXNSTU+1, 1, MAXCOV+MAXCOVLOC+3+MAXSIMS); augout = dmatrix(1, MAXNSTU+1, 1, MAXCOV+MAXCOVLOC+3+MAXSIMS);
14
1990
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 convert an object of this type to the following type?
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10542
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10309
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7600
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6840
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5496
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3795
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2968
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.