小编mcx*_*ain的帖子

如何在 Ada 中读取 C Void 指针?

有以下 C-Function 以 void 指针作为参数:

int read(void *buf, size_t num);
Run Code Online (Sandbox Code Playgroud)

int => 返回读取操作是否成功。
void *buf => c void 无符号字节缓冲区指针作为函数参数。
size_t num => 应填充的字节缓冲区的大小。

目前我有以下 Ada 实现:

with Ada.Text_IO;
with System;
with Interfaces.C;

use Ada.Text_IO;
use Interfaces.C;

procedure Main is

      -- Imported C function
      function Read(Buf:System.Address; Num:int) return int;
      pragma Import(C, Read, "read");

      -- Byte Array Type
      type Byte_Type is mod 2**8;
      for Byte_Type'Size use 8;

      type Byte_Array_Type is array(Positive range <>) of Byte_Type;

      -- Initialize
      Buffer_Check:int;
      Buffer_Size:Positive:=10;
      Buffer_Array:Byte_Array_Type(1 .. Buffer_Size):=(others …
Run Code Online (Sandbox Code Playgroud)

c buffer pointers ada void-pointers

3
推荐指数
1
解决办法
179
查看次数

标签 统计

ada ×1

buffer ×1

c ×1

pointers ×1

void-pointers ×1