私はRcppを初めて使用するので、まだ盲目的に自分の道を見つけています。問題の長所と短所は、ポインターを生成するオブジェクトがあり、そのポインターをRに返したいということです。
ポインタをにキャストすると必要な精度が維持されることがわかりましたが、。size_t
でそれを返すことはできないようですwrap
。
以下のコードでは、willを返すだけでunsigned long int
コンパイルされ、他のコードはエラーをスローします。スペースの都合上、ここには含めません。そして私のオブジェクトでは、にキャストすると、unsigned long int
精度が失われたためにコンパイラが失敗します(これはすべてコメントアウトされている最初のブロックにあります)。
このタイプのオブジェクトのテンプレートをsize_t
作成するという選択肢を避けるために、私のニーズにはsを使用するだけで十分です。wrap
変更ログを確認しましたが、size_tがサポートされているようです。概要では、のwrap
サポートも提案されていsize_t
ます。
#include <Rcpp.h>
#include <iostream>
using namespace Rcpp;
using namespace std;
extern "C" SEXP attempt()
{
// this block if uncommented gives compile error that converting a pointer to unsigned long int loses precision
// also, wrapping the pointer &f causes a compilation error
//int f = 314;
//unsigned long int theVar_longint = (unsigned long int) &f;
//cout << "pointer: " << &f << endl;
//return(wrap(&f));
// This block makes an arbitrary value into a size_t, unsigned long int and unsigned long long int
size_t theVar_sizet = (size_t) 383762523;
unsigned long int theVar_longint = (unsigned long int) 383762523;
unsigned long long int theVar_longlongint = (unsigned long long int) 383762523;
// prints the results
cout << "size_t: " << theVar_sizet << endl;
cout << "longint: " << theVar_longint << endl;
cout << "longlongint: " << theVar_longlongint << endl;
// only the first line returns properly, the others cause errors in compilation
return(wrap(theVar_longint));
//return(wrap(theVar_longlongint));
//return(wrap(theVar_sizet));
}