Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 教育他为什么不需要精神错乱?真的,他被问到怎么做了。我不知道他这样做的理由是什么,你也不知道。我们都知道这样做的理由非常少。你觉得他一定是这样做的,因为他不知道什么更好(他可能不知道),你的工作就是告诉他不应该这样做以及为什么。那很好。我不觉得我需要这么做_C++_C_Java Native Interface - Fatal编程技术网

C++ 教育他为什么不需要精神错乱?真的,他被问到怎么做了。我不知道他这样做的理由是什么,你也不知道。我们都知道这样做的理由非常少。你觉得他一定是这样做的,因为他不知道什么更好(他可能不知道),你的工作就是告诉他不应该这样做以及为什么。那很好。我不觉得我需要这么做

C++ 教育他为什么不需要精神错乱?真的,他被问到怎么做了。我不知道他这样做的理由是什么,你也不知道。我们都知道这样做的理由非常少。你觉得他一定是这样做的,因为他不知道什么更好(他可能不知道),你的工作就是告诉他不应该这样做以及为什么。那很好。我不觉得我需要这么做,c++,c,java-native-interface,C++,C,Java Native Interface,教育他为什么不需要精神错乱?真的,他被问到怎么做了。我不知道他这样做的理由是什么,你也不知道。我们都知道这样做的理由非常少。你觉得他一定是这样做的,因为他不知道什么更好(他可能不知道),你的工作就是告诉他不应该这样做以及为什么。那很好。我不觉得我需要这么做,因为我不确定他是否知道得更好,因为即使他不知道,好吧,有时候人们发现自己的错误比让别人指出要好。拜托,先生们。我理解这是一个奇怪的问题,我之所以使用它是因为这是为了在jni库中使用,它将ogg vorbis库连接到java中,这样我就可以在j


教育他为什么不需要精神错乱?真的,他被问到怎么做了。我不知道他这样做的理由是什么,你也不知道。我们都知道这样做的理由非常少。你觉得他一定是这样做的,因为他不知道什么更好(他可能不知道),你的工作就是告诉他不应该这样做以及为什么。那很好。我不觉得我需要这么做,因为我不确定他是否知道得更好,因为即使他不知道,好吧,有时候人们发现自己的错误比让别人指出要好。拜托,先生们。我理解这是一个奇怪的问题,我之所以使用它是因为这是为了在jni库中使用,它将ogg vorbis库连接到java中,这样我就可以在java应用程序中传输vorbis声音。不可能直接将结构从本机传递到java代码(出于明显的原因),因此我的方法是将指针本身作为整数值传递到java程序中,然后在需要在本机代码中再次使用时将其传递回。请注意,不应从
malloc(3)强制转换返回值
——只需将
包括在内,您将获得
malloc(3)
原型,它允许编译器为您处理所有事情。这些强制转换可以隐藏编译器警告消息,提醒您注意代码中的错误。很可能
long
不够长,无法保存指针值。使用
(u)intptr\u t
size\u t
long-long
可能会有更好的结果。出于好奇,为什么要使用long-int?Alex,不应该涉及运气,因为
DummyStructure**
工作得很好。@Keitherwin:既然这个问题被标记为
jni
,我猜他想将指针强制转换为可以作为句柄传递给Java应用程序的类型。如果
long int
不足以容纳指针,则不应编译
long int
到指针类型的转换。如果
long int
小于指针大小,则第二次强制转换将不会编译。(在现代机器上不太可能,但我曾在指针为48位,但长int只有32位的系统上工作过。)
typedef struct
{
    int rate;
    int duration;
} DummyStructure;
//
DummyStructure* structure;
DummyStructure* structure2;
long int point;

//
structure = (DummyStructure*)malloc(sizeof(DummyStructure));
structure->rate = 19;
structure->duration = 92;
point = (long int)&structure;

// now i'd like to set structure2 to the same memory location as 1.
// point is the 8-byte int location (i assume?) of structure.
// so naturally i'd assume that by casting as a DummyStructure pointer
// that long int would act as a pointer to that 1.

// It doesn't.
structure2 = (DummyStructure*)point;
DummyStructure** point;

structure = malloc(sizeof(DummyStructure));
structure->rate = 19;
structure->duration = 92;
point = &structure;

structure2 = *point;
structure2 = *((DummyStructure*)point);
printf("a regular pointer is %u bytes, long int is %u",
  (unsigned int) sizeof structure, (unsigned int) sizeof point);
long int point = reinterpret_cast<long int>(structure);
DummyStructure* structure2 = reinterpret_cast<DummyStructure*>(point);
point = (long int)&structure;
typedef struct
{
    int rate;
    int duration;
} DummyStructure;

DummyStructure* structure;
DummyStructure* structure2;
long int **point;
structure = (DummyStructure*)malloc(sizeof(DummyStructure));
structure->rate = 19;
structure->duration = 92;
point = (long int **)&structure;
structure2 = (DummyStructure*)*point;
structure2 = *(DummyStructure**)point;
structure2 = structure;
jlong forJNI = 0;
*reinterpret_cast<DummyStructure*>( &forJNI ) = structure;
//  ...
structure2 = *reinterpret_cast<DummyStructure*>( &forJNI );