c指针结构为c# [英] c pointer in structure to c#
本文介绍了c指针结构为c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我有这样的交流结构:
typedef struct{
int batch_normalize;
int *batch;
}layer;
我将其转换为c#:
[StructLayout(LayoutKind.Sequential)]
public struct layer{
public int batch_normalize;
public int batch;
}
c函数是:
void Test(int b, int bn){
layer l;
l.batch_normalize = bn;
l.batch = calloc(b, sizeof(int));
}
我需要从dll调用此函数,请我如何解决这个难题。
i need to call this function from dll , please how i can solve this piece of puzzle.
谢谢
Lafi
推荐答案
指针不等同于int。指针是什么?
A pointer is not equivalent to an int, ever. What is that a pointer to?
[StructLayout(LayoutKind.Sequential)]
public struct layer
{
public int batch_normalize;
public IntPtr batch;
}
C函数不能正确。它将积分文字5指定给指针。虽然在旧版本的C ++中是合法的,但在新版本中这是不合适的,因为它没有意义。你不能(很可能)在
5.地址有任何东西。
The C function cannot be right. It is assigning the integral literal 5 to a pointer. While legal in the older versions of C++ this is being deprecated in newer versions because it doesn't make sense. You cannot (most likely) have anything at address
5.
这篇关于c指针结构为c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文