Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.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
Swig[C->;Python]:如何处理原语类型的输入或输出函数参数?_Python_C_Swig - Fatal编程技术网

Swig[C->;Python]:如何处理原语类型的输入或输出函数参数?

Swig[C->;Python]:如何处理原语类型的输入或输出函数参数?,python,c,swig,Python,C,Swig,例如,我有 我的类型 typedef uint16_t my_type_1; typedef uint8_t my_type_2; 我的工作类型 int my_func(my_type_1 * arg1, my_type_2 * arg2, my_type_3 *arg3) { *args3 = *arg1 + *arg2; return 0; } 如何定义接口文件以将其包装到python?假设您在my_types.h中没有声明my_func,那么您的接口可以变成: %mod

例如,我有

我的类型

typedef uint16_t my_type_1;
typedef uint8_t my_type_2;
我的工作类型

int my_func(my_type_1 * arg1, my_type_2 * arg2, my_type_3 *arg3)
{
    *args3 = *arg1 + *arg2;
    return 0;
}
如何定义接口文件以将其包装到python?

假设您在my_types.h中没有声明
my_func
,那么您的接口可以变成:

%module test

%{
#include "my_types.h"
%}

%include <stdint.i>

%include "my_types.h"

%apply uint16_t *INPUT { my_type_1 * arg1 };
%apply uint8_t *INPUT { my_type_2 * arg2 };
%apply uint16_t *OUTPUT { my_type_1 *arg3 };

int my_func(my_type_1 * arg1, my_type_2 * arg2, my_type_1 *arg3);

您的“实际”返回是元组中的位置0,第一个输出是位置1。

您的问题中有一些输入错误-没有
my\u type\u 3
typedef,并且在
my\u func
的定义中有args3而不是arg3。
import test

print test.my_func(100, 50)[1]