- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
pointer": Wrong Type Argument in Position 1-6ren"> pointer": Wrong Type Argument in Position 1-因此 Guile 过程“procedure->pointer”采用返回类型、Scheme 函数和参数类型列表,并返回 C 函数指针。 过程->指针:(返回类型、Scheme 函数、参数类型列表)-> -6ren">
因此 Guile 过程“procedure->pointer”采用返回类型、Scheme 函数和参数类型列表,并返回 C 函数指针。
过程->指针:(返回类型、Scheme 函数、参数类型列表)-> C 函数指针
我的问题是,如果我在 C 中定义自定义类型“foo”(通过 typedef 或结构定义),我如何在 Guile 中注册它以便我可以使用“foo”作为返回类型或参数输入过程->指针?我会向 procedure->pointer 传递一个名为“foo”的符号还是一个名为“foo”的 Scheme 变量?
编辑:我想这样调用:
foo (*c_foo_func)(foo) = scm_procedure_to_pointer(foo, scm_foo_func, scm_list_1(foo));
最佳答案
在 C 中,typedef
声明创建同义词,而不是新类型。抬头发现真实类型的声明。例如,签名H5Fclose
是
herr_t H5Fclose(hid_t file_id);
类型herr_t
和hid_t
在HDF5 头文件中声明为
typedef int herr_t;
typedef int hid_t;
因此,要创建一个包装 H5Fclose
的 Scheme 过程,请使用
(pointer->procedure int (dynamic-func "H5Fclose" ...) (list int))
或者,可以在 Scheme 中定义相同的同义词:
(define herr_t int)
(define hid_t int)
然后就可以写了
(pointer->procedure herr_t (dynamic-func "H5Fclose" ...) (list hid_t))
在 C 语言中,结构通常通过指针传递给函数或从函数中传递出来。为了例如,回调的签名传递给 H5Literate是
herr_t op(hid_t group, const char *name, const H5L_info_t *info, void *op_data);
H5L_info_t
是一种通过指针传递的结构类型。
回调的参数类型在Scheme中的表示是
(list int '* '* '*)
函数 make-c-struct
和 parse-c-struct
( reference )创建和读取结构指针。他们需要知道的布局struct,以列表的形式给出,其中包含结构成员的类型。
Guile 也支持按值传递结构,尽管它不是记录在案。函数 pointer->procedure
和过程->指针
( reference )采用返回和参数类型。表示传递的结构按值,使用包含结构成员类型的列表。
Scheme 中结构值的操作仍然使用make-c-struct
和 parse-c-struct
(结构值是自动转换为指针并返回)。
以下示例演示如何将 Scheme 过程传递给C 函数 H5Literate
。它是“迭代”的翻译Groups w/H5Literate” 来自 HDF5 CExamples。
示例数据文件 h5ex_g_iterate.h5需要在工作目录中。
需要大量代码来复制类型和常量HDF5 header ,但实际程序很短(在非常结束)。
(use-modules
(system foreign)
(rnrs bytevectors))
(define libhdf5 (dynamic-link "libhdf5"))
;; HDF5 typedefs
;; typedef int herr_t;
(define herr_t int)
;; typedef int hid_t;
(define hid_t int)
;; typedef enum H5_index_t {
;; H5_INDEX_UNKNOWN = -1, /* Unknown index type */
;; H5_INDEX_NAME, /* Index on names */
;; H5_INDEX_CRT_ORDER, /* Index on creation order */
;; H5_INDEX_N /* Number of indices defined */
;; } H5_index_t;
(define H5_index_t int)
(define H5_INDEX_NAME 0)
;; typedef enum {
;; H5_ITER_UNKNOWN = -1, /* Unknown order */
;; H5_ITER_INC, /* Increasing order */
;; H5_ITER_DEC, /* Decreasing order */
;; H5_ITER_NATIVE, /* No particular order, whatever is fastest */
;; H5_ITER_N /* Number of iteration orders */
;; } H5_iter_order_t;
(define H5_iter_order_t int)
(define H5_ITER_NATIVE 2)
;; typedef herr_t (*H5L_iterate_t)(hid_t group, const char *name, const H5L_info_t *info,
;; void *op_data);
(define H5L_iterate_t '*)
;; typedef uint64_t haddr_t;
(define haddr_t uint64)
;; typedef enum H5O_type_t {
;; H5O_TYPE_UNKNOWN = -1, /* Unknown object type */
;; H5O_TYPE_GROUP, /* Object is a group */
;; H5O_TYPE_DATASET, /* Object is a dataset */
;; H5O_TYPE_NAMED_DATATYPE, /* Object is a named data type */
;; H5O_TYPE_NTYPES /* Number of different object types (must be last!) */
;; } H5O_type_t;
(define H5O_type_t int)
(define H5O_TYPE_GROUP 0)
(define H5O_TYPE_DATASET 1)
(define H5O_TYPE_NAMED_DATATYPE 2)
;; time_t is long on POSIX systems
(define time_t long)
;; typedef unsigned long long hsize_t;
;; (system foreign) doesn't have long long, use uint64 and cross our fingers
(define hsize_t uint64)
;; typedef struct H5O_hdr_info_t {
;; unsigned version; /* Version number of header format in file */
;; unsigned nmesgs; /* Number of object header messages */
;; unsigned nchunks; /* Number of object header chunks */
;; unsigned flags; /* Object header status flags */
;; struct {
;; hsize_t total; /* Total space for storing object header in file */
;; hsize_t meta; /* Space within header for object header metadata information */
;; hsize_t mesg; /* Space within header for actual message information */
;; hsize_t free; /* Free space within object header */
;; } space;
;; struct {
;; uint64_t present; /* Flags to indicate presence of message type in header */
;; uint64_t shared; /* Flags to indicate message type is shared in header */
;; } mesg;
;; } H5O_hdr_info_t;
(define H5O_hdr_info_t
(list
unsigned-int
unsigned-int
unsigned-int
unsigned-int
(list
hsize_t
hsize_t
hsize_t
hsize_t)
(list
uint64
uint64)))
;; typedef struct H5_ih_info_t {
;; hsize_t index_size; /* btree and/or list */
;; hsize_t heap_size;
;; } H5_ih_info_t;
(define H5_ih_info_t
(list
hsize_t
hsize_t))
;; typedef struct H5O_info_t {
;; unsigned long fileno; /* File number that object is located in */
;; haddr_t addr; /* Object address in file */
;; H5O_type_t type; /* Basic object type (group, dataset, etc.) */
;; unsigned rc; /* Reference count of object */
;; time_t atime; /* Access time */
;; time_t mtime; /* Modification time */
;; time_t ctime; /* Change time */
;; time_t btime; /* Birth time */
;; hsize_t num_attrs; /* # of attributes attached to object */
;; H5O_hdr_info_t hdr; /* Object header information */
;; /* Extra metadata storage for obj & attributes */
;; struct {
;; H5_ih_info_t obj; /* v1/v2 B-tree & local/fractal heap for groups, B-tree for chunked datasets */
;; H5_ih_info_t attr; /* v2 B-tree & heap for attributes */
;; } meta_size;
;; } H5O_info_t;
(define H5O_info_t
(list
unsigned-long
haddr_t
H5O_type_t
unsigned-int
time_t
time_t
time_t
time_t
hsize_t
H5O_hdr_info_t
(list
H5_ih_info_t
H5_ih_info_t)))
(define (make-H5O_info_t)
"Returns a pointer to a zero-initialized H50_info_t struct."
(bytevector->pointer (make-bytevector (sizeof H5O_info_t) 0)))
(define (parse-H5O_info_t foreign)
(parse-c-struct foreign H5O_info_t))
(define (H5O_info_t-type vals)
(list-ref vals 2))
;; HDF5 constants
;; #define H5F_ACC_RDONLY (H5CHECK 0x0000u)
(define H5F_ACC_RDONLY 0)
;; #define H5P_DEFAULT (hid_t)0
(define H5P_DEFAULT 0)
;; HDF5 functions
;; hid_t
;; H5Fopen(const char *filename, unsigned flags, hid_t fapl_id);
(define H5Fopen
(pointer->procedure
hid_t
(dynamic-func "H5Fopen" libhdf5)
(list '* unsigned-int hid_t)))
;; herr_t
;; H5Literate(hid_t grp_id, H5_index_t idx_type, H5_iter_order_t order,
;; hsize_t *idx_p, H5L_iterate_t op, void *op_data);
(define H5Literate
(pointer->procedure
herr_t
(dynamic-func "H5Literate" libhdf5)
(list hid_t H5_index_t H5_iter_order_t '* H5L_iterate_t '*)))
;; herr_t
;; H5Fclose(hid_t file_id);
(define H5Fclose
(pointer->procedure
herr_t
(dynamic-func "H5Fclose" libhdf5)
(list hid_t)))
;; herr_t
;; H5Oget_info_by_name(hid_t loc_id, const char *name, H5O_info_t *oinfo, hid_t lapl_id);
(define H5Oget_info_by_name
(pointer->procedure
herr_t
(dynamic-func "H5Oget_info_by_name" libhdf5)
(list hid_t '* '* hid_t)))
(define FILE "h5ex_g_iterate.h5")
(define (main)
(let ((status 0)
(file (H5Fopen (string->pointer FILE) H5F_ACC_RDONLY H5P_DEFAULT)))
(display "Objects in root group:\n")
(set! status (H5Literate file H5_INDEX_NAME H5_ITER_NATIVE %null-pointer
op_func_ptr %null-pointer))
(set! status (H5Fclose file))
0))
;; Operator function. Prints the name and type of the object
;; being examined.
;;
;; C signature:
;; herr_t op_func (hid_t loc_id, const char *name, const H5L_info_t *info,
;; void *operator_data)
(define (op_func loc_id name info operator_data)
(let ((status 0)
(name-str (pointer->string name))
(infobuf (make-H5O_info_t)))
(set! status (H5Oget_info_by_name loc_id name infobuf H5P_DEFAULT))
(let ((type (H5O_info_t-type (parse-H5O_info_t infobuf))))
(cond
((= type H5O_TYPE_GROUP)
(format #t " Group: ~a\n" name-str))
((= type H5O_TYPE_DATASET)
(format #t " Dataset: ~a\n" name-str))
((= type H5O_TYPE_NAMED_DATATYPE)
(format #t " Datatype: ~a\n" name-str))
(else
(format #t " Unknown: ~a\n" name-str))))
0))
(define op_func_ptr (procedure->pointer herr_t op_func (list hid_t '* '* '*)))
(main)
关于c - Guile 程序错误 "procedure->pointer": Wrong Type Argument in Position 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39798793/
例如,如果我的程序名称是 test.c 然后对于以下运行命令,argc = 2 而不是 4。 $test abc pqr* *xyz* 最佳答案 尝试运行: $ echo abc pqr* *xyz*
我正在尝试使用一个容器来显示TextField,但是该容器不喜欢我的操作顺序。这是我的代码: Widget build(BuildContext context) { return Scaffol
我有以下代码: class MetricGoogleGateway extends AMetricGateway{ constructor(id, name, token) {
我像这样调用下面的对象方法。 new Cout( elem1 ).load( 'body' ) new COut( elem1 ).display( 'email' ) 我一次只使用一个实例。因为我一
我正在尝试使用 C++11 中的可变参数函数模板,并通过如下代码了解了基本思想: void helper() { std::cout void helper( T&& arg ) {
在学习 ExtJS 4 时,我发现在定义一个新类时,在 initComponent 中方法可以使用 this.callParent(arguments) 调用父类的构造函数. 我想知道这个 argum
使用 XCode 9,Beta 3。Swift 4。 statsView.createButton("Button name") { [weak self] Void in //stuff st
以下代码将打印1: (function (arguments) { console.log(arguments); }(1, 2)); 实际上,arguments 对象已被覆盖。是否可以恢复函
/** * @param $name * @return Response * @Route ("/afficheN/{name}",name="afficheN") */ public fu
我习惯使用Scala scopt用于命令行选项解析。您可以选择参数是否为 .required()通过调用刚刚显示的函数。 如何定义仅在定义了另一个参数时才需要的参数? 例如,我有一个标志 --writ
所以这是我的代码: def is_valid_move(board, column): '''Returns True if and only if there is an o
我试图在这里运行此代码: threads = [threading.Thread(name='ThreadNumber{}'.format(n),target=SB, args(shoe_type,m
在静态类型函数编程语言(例如 Standard ML、F#、OCaml 和 Haskell)中,编写函数时通常将参数彼此分开,并通过空格与函数名称分开: let add a b = a + b
function validateArguments(args) { if(args.length 2) { throw new RangeError("Invalid amo
我正在使用 Django 1.5 并尝试将参数传递到我的 URL。当我使用前两个参数时,下面的代码工作正常,使用第三个参数时我收到错误。我已经引用了新的 Django 1.5 更新中的 url 用法,
我刚刚开始使用 ember js 并且多次被这个功能绊倒 有人可以简要介绍一下 this._super() 的使用,并解释 ...arguments 的重要性 谢谢 最佳答案 每当您覆盖类/函数(例如
这个问题在这里已经有了答案: How to fix an "Argument passed to call that takes no arguments" error? (2 个答案) 关闭 3
我正在创建一个简单的登录注册应用程序。但是我遇到了错误,我不知道如何解决,请帮忙!这是我的代码: // // ViewController.swift // CHLogbook-Applicati
我是 Swift 的初学者。我尝试创建一个表示 Meal 的简单类。 它有一些属性和一个返回可选的构造函数 但是当我尝试测试它或在任何地方实例化它时,我得到的只是一个错误。似乎无法弄清楚发生了什么。
我有一个在特殊环境下运行其他程序的系统程序: cset shield -e PROGRAM .现在要运行一个 java 程序,我输入了 cset shield -e java PROGRAM ,但这不
我是一名优秀的程序员,十分优秀!