
C#如何调用指针作为形参的函数
main(){char[]tmpstr=newchar[256];byte[]datbuf=newbyte[256];l=fun(tmpstr,datbuf);}unsa...
main()
{
char[] tmpstr = new char[256];
byte[] datbuf = new byte[256];
l = fun(tmpstr,datbuf);
}
unsafe public int fun(char* hexstr, void* datbuf)
{}
l = fun(tmpstr,datbuf)这一句怎么写,也就是实参怎么写,才能调用函数fun()?
望高手指点! 展开
{
char[] tmpstr = new char[256];
byte[] datbuf = new byte[256];
l = fun(tmpstr,datbuf);
}
unsafe public int fun(char* hexstr, void* datbuf)
{}
l = fun(tmpstr,datbuf)这一句怎么写,也就是实参怎么写,才能调用函数fun()?
望高手指点! 展开
展开全部
指向数组的指针就是数据第一个元素的地址, 所以char* ptr0 = tmpstr就是定义一个指向数组的指针.
代码如下
char[] tmpstr = new char[256];
byte[] datbuf = new byte[256];
fixed (char* ptr0 = tmpstr)
{
fixed (byte* ptr1 = datbuf)
{
int r = fun(ptr0, ptr1);
}
}
代码如下
char[] tmpstr = new char[256];
byte[] datbuf = new byte[256];
fixed (char* ptr0 = tmpstr)
{
fixed (byte* ptr1 = datbuf)
{
int r = fun(ptr0, ptr1);
}
}
展开全部
fixed (void* ptr0 = tmpstr, ptr1 = datbuf)
l = fun((char*)ptr0, ptr1);
l = fun((char*)ptr0, ptr1);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public int fun(StringBuffer sb1,StringBuffer sb2)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询