我正在编写一个程序,它使用JNI与简单的c程序进行交互.我创建了以下程序:
public static void main(String[] args) {
Hello h = new Hello();
System.out.println("before");
int number = h.sayHello();
System.out.println(number);
System.out.println("after");
}
Run Code Online (Sandbox Code Playgroud)
和
JNIEXPORT int JNICALL Java_Hello_sayHello (JNIEnv *env, jobject obj) {
printf("Hello JNI\n");
return 10;
}
Run Code Online (Sandbox Code Playgroud)
令我惊讶的是这个程序返回:
before
10
after
Hello JNI
Run Code Online (Sandbox Code Playgroud)
对我来说这很奇怪,因为很明显c程序是在"before"和"after"语句之间执行的(打印数字10).但是为什么调用printf语句时不会执行它.它是否以某种方式被jvm阻止,因为只允许一个程序同时写入输出?有没有办法纠正这种行为?
考虑以下VHDL记录:
type big_record_t is record
field_a : unsigned(15 downto 0);
field_b : unsigned(23 downto 0);
end record;
Run Code Online (Sandbox Code Playgroud)
是否可以在记录字段上获取属性而无需实例化记录本身?例如
signal ex : unsigned(big_record_t.field_a'range);
Run Code Online (Sandbox Code Playgroud)
modelsim报告以下错误:
(vcom-1260) Type mark (big_record_t) cannot be prefix of selected name.
Run Code Online (Sandbox Code Playgroud)
我知道获取实例化信号的属性是可能的,但对于这种特定情况,我想从类型本身获取类型属性.
我正在使用一个库在 C++、VHDL 和 SystemVerilog 之间共享数据。它使用代码生成器来构建包含适当字段的数据结构。想想 ac 类型的数据结构。我想生成包含数据结构和读/写函数的 python 代码,以将数据结构的内容从 / 设置和写入文件。
为此,我尝试编写一个程序,打印基类中的所有变量以及子类的更新,但不打印子类变量。
这个想法是,类 A 是实际的 VHDL/SystemVerilog/C++ 记录/结构,类 B 包含进行处理并生成类 A 中的值的逻辑。
例如:
class A(object):
def __init__(self):
self.asd = "Test string"
self.foo = 123
def write(self):
print self.__dict__
class B(A):
def __init__(self):
A.__init__(self)
self.bar = 456
self.foo += 1
def write(self):
super(B, self).write()
Run Code Online (Sandbox Code Playgroud)
调用 B.write() 应产生以下结果:(注意 foo 的递增值)
“asd:测试字符串,foo:124”
但它却产生了
“asd:测试字符串,bar:456,foo:124”。
有没有办法只获取基类变量?我可以将基本字典与子类字典进行比较,并只打印两者中出现的值,但这感觉不是一个干净的方法。