- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为 Cgraph 创建 Perl6 绑定(bind),其中一个结构为其某些属性设置了位字段,其值低于 8。我应该如何在我的模块中表示它?
我尝试使用 is nativesize(x)
定义自定义类型trait,但 CStructs 仅支持 8 位宽的倍数的类型。
C 示例代码:
struct Agtag_s {
unsigned objtype:2;
}
my native objtype is repr('P6int') is Int is nativesize(2) is export { }
class Agtag is repr('CStruct') is export {
has objtype $.object-type;
}
CStruct only supports native types that are a multiple of 8 bits wide (was passed: 2)
最佳答案
这是一个例子。我假设一个函数 use_struct()
在库中定义 libslib
:
#include <stdio.h>
struct Agtag_s {
unsigned objtype:2;
unsigned footype:4;
unsigned bartype:6;
};
void use_struct (struct Agtag_s *s) {
printf("sizeof(struct Agtag_s): %ld\n", sizeof( struct Agtag_s ));
printf("objtype = %d\n", s->objtype);
printf("footype = %d\n", s->footype);
printf("bartype = %d\n", s->bartype);
s->objtype = 3;
s->footype = 13;
s->bartype = 55;
}
use v6;
use NativeCall;
class Agtag is repr('CStruct') is export {
has int32 $.bitfield is rw;
}
sub use_struct(Agtag $s is rw) is native("./libslib.so") { * };
my $s = Agtag.new();
my $objtype = 1;
my $footype = 7;
my $bartype = 31;
$s.bitfield = $objtype +| ($footype +< 2 ) +| ($bartype +< 6);
say "Calling library function..";
say "--------------------------";
use_struct( $s );
say "After call..";
say "------------";
say "objtype = ", $s.bitfield +& 3;
say "footype = ", ($s.bitfield +> 2) +& 15;
say "bartype = ", ($s.bitfield +> 6) +& 63;
Calling library function..
--------------------------
sizeof(struct Agtag_s): 4
objtype = 1
footype = 7
bartype = 31
After call..
------------
objtype = 3
footype = 13
bartype = 55
关于raku - NativeCall 中的位域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56775926/
我正在尝试为 Cgraph 创建 Perl6 绑定(bind),其中一个结构为其某些属性设置了位字段,其值低于 8。我应该如何在我的模块中表示它? 我尝试使用 is nativesize(x) 定义自
我目前正在尝试使用 Java 中的 NTX 索引访问 DBF。我有一个多年前的 Artemis 引擎(现在的 ApolloDB)的副本,它可以在 VB6 中执行此操作。它使用 3 个 DLL,主要是
我有两个库,我想调用第一个库中的例程,然后它们调用第二个库中的例程,但由于这些符号未定义而崩溃。即使我不想调用它们,是否可以从库 XX 中说“加载这些符号”? teSTLib1.c: #include
我在 Buf 中有一大块内存我想传递给 C 库,但该库将使用超出单个调用生命周期的内存。 我知道这可能会有问题,因为垃圾收集器可以移动内存。 用于传递 Str , Nativecall docs 说“
我正在为 Editline 编写绑定(bind);它的功能之一, history ,为库的这一部分完成大部分工作,但有几个可能的签名: :(Pointer[Internal], Pointer[Eve
软呢帽 33 乐 我正在尝试使用 Raku 的 NativeCall 与 libX11.so 对话以打印出我的屏幕和显示: use NativeCall; class Display is repr(
https://docs.perl6.org/language/nativecall "As you may have predicted by now, a NULL pointer is re
我有一个第三方 C 库,它定义了类似于以下内容的结构: struct myStruct { int a; int b; char str1[32]; char str2[32]; };
试图与一个 C 库接口(interface),该库采用一个结构,该结构带有一堆指向它在各个点调用的函数的指针。 像这样的东西: struct callbacks { int (*foo)(in
Perl 6 docs列出一堆类型。其中一些,例如 Str ,有更复杂的装箱/拆箱行为。 是否可以定义我自己的类型,指定我自己的装箱/拆箱例程?对于一个特定的项目,我有一堆我正在重用的类型,并且基本上
我正在尝试使用 NativeCall 与一些 C 函数交互。 对于一种情况,我需要传入由函数,因此它需要一个指向指针“void **”的指针。 我尝试过这样的: class Foo { has
我正在尝试使用 NativeCall 与一些 C 函数交互。 我有一个简单的 C 结构体和一个需要它们数组的函数。 struct foo { int x; char *s; }; st
我正在尝试移植 this code到 Perl6。虽然我可以调用 GetStdHandle、GetConsoleMode 和 SetConsoleMode,但当我尝试调用 ReadConsoleInp
有没有一种方便的方法来处理在不同平台上可能具有不同值的 C typedef? 例如 #if defined(_WIN32) #define foo_t int32_t #elif define
我希望能够在具有 REPR CStruct/CPointer 的类中使用双指针: typedef struct CipherContext { void *cipher;
在 Windows 和 Linux 上使用 NativeCall 为 C 库发布 Perl 6 绑定(bind)的最佳策略是什么? 开发者是否需要同时编译.dll和.so文件并用perl6代码上传到g
我正在使用 NativeCall 来熟悉 Perl6 的那一面。当然,我想先加载 libstatgrab(还有什么?)。 所以我从最简单的部分开始——主机信息。由于还没有集群支持,这只是一个结果——不
我正在使用 NativeCall 接口(interface)。 该库将多次调用我的回调函数。 这很好用。我可以用正确的方式声明我的回调 签名,将其作为 &callback 传递,库只调用 sub 美好
这些代码片段可能看起来很奇怪,这是因为我从我的原始代码开始并切断了部分,直到我到达重现错误的最小指令集。所以忍受表面上的无用。 perl6模块有两个,一个use s另一个,和一个程序。 这是第一个模块
有没有办法在 CStruct 中声明一个对象数组? struct my_struct { int foo; int bar; char somestring[80]; }; c
我是一名优秀的程序员,十分优秀!