传递一个C ++数组Ada95的 [英] Passing a C++ array to Ada95

查看:113
本文介绍了传递一个C ++数组Ada95的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过从C ++到Ada的无符号整数数组。阿达洛夫莱斯教程指出的阿达阵列对应的指针在C ++中数组的第一个元素。

I'm trying to pass an array of unsigned integers from C++ to Ada. The Ada Lovelace tutorial states that an Ada array corresponds to a pointer to the first element of an array in C++.

下面是我想要做的。

C ++

unsigned int buffer[bufferSize];

...

unsigned int* getBuffer() {
    return buffer;
}

阿达

pragma Import (C, C_Get_Buffer, "getBuffer");

...

function C_Get_Buffer returns System.Address;

...

Buffer : array (1 .. Buffer_Size) of Interfaces.C.Unsigned;

...

Buffer'Address := C_Get_Buffer;

我发现Buffer'Address却无法分配。什么是去传递一个数组从C到小梅的正确方法是什么?

I'm finding that Buffer'Address cannot be assigned however. What is the correct way to go about passing an array from C to Ada?

谢谢!

推荐答案

这将做你问(我没有费心 BUFFER_SIZE

This will do as you ask (I didn’t bother with Buffer_Size):

function C_Get_Buffer return System.Address;
pragma Import (C, C_Get_Buffer, "getBuffer");
Buffer_Address : constant System.Address := C_Get_Buffer;
Buffer : array (1 .. 10) of Interfaces.C.unsigned;
for Buffer'Address use Buffer_Address;

不过,这可能是合适的,作为实现同样的事情更短的方式:

However, this might be appropriate as a shorter way of achieving the same thing:

Buffer : array (1 .. 10) of Interfaces.C.unsigned;
pragma Import (C, Buffer, "buffer");

这篇关于传递一个C ++数组Ada95的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆