conversion from Ct type to C type

Problem :  The code below is not allowed.

#include <iostream>
#include "ct.h"
using namespace std;
using namespace Ct;
int main(int argc, char **argv) {
Tuple<3, F64> xyz(1.0, 2.0, 3.0);
F64 x = xyz.get<0>();
double d = x; // how to formulate this line?
cout << d << endl;

Environment : Ct Windows Beta, All versions of Visual Studio

Root Cause : Ct code has to happen in the Ct function, and the C++ to Ct function call has to go thru remote calls. Even in Ct functions, we don’t allow the assignment of Ct scalars to C variables. All C++ and Ct data exchange has to happen at remote call sites (thru binding constructors) or explicit copyIn/copyOut sites. Ct does not have the explicit copyOut interface for the scalar.

Resolution : 

If you want to copy out the value of a Ct scalar leak handle or a Ct global scalar handle, the example is like:

template <Typename T>
void scalarCopy( T src, T& dest )
dest = src;

template <Typename T>
typename T::cType copyOut(T v)
typedef typename T::cType cType;
cType _v;
T tv( &_v );
rcall( scalarCopy<T> )( v, tv );
return _v;

I32 ctValue = …;

_I32 v = copyOut( ctValue );

We deliberately require such conversion to be happening only at specific sites because frequent conversions would be perf killer. Moreover, if the computation to put into the Ct functions is too fine-grained, we don’t suggest rewriting the computation in Ct.

For more complete information about compiler optimizations, see our Optimization Notice.