在jupyter记事本下运行xeus(v0.13.0)允许在代码单元格中运行C++代码,有时..。注意:这是一个与木星笔记本实现的问题,Xeus -running在命令行上没有这些问题。
例如,它似乎随机地记住了某些定义,而忘记了其他定义:
在第1牢房:
#include <iostream>
using std::cout;
using std::endl;在第2牢房:
cout << "D\n";
cout <<"D" << endl;给予:
input_line_9:3:15: error: use of undeclared identifier 'endl'; did you mean 'std::endl'?
cout <<"D" << endl;
^~~~
std::endl
/home/don/miniconda3/envs/xeus-cling/bin/../lib/gcc/x86_64-conda-linux-gnu/9.3.0/../../../../x86_64-conda-linux-gnu/include/c++/9.3.0/ostream:599:5: note: 'std::endl' declared here
endl(basic_ostream<_CharT, _Traits>& __os)而且,对于我来说,它是否会接受函数定义似乎是不可预测的。下面是一个示例:
在第1牢房:
#include <iostream>第2室:
using namespace std;
void f2(){
cout << "HI\n";
}给予:
input_line_8:3:10: error: function definition is not allowed here
void f2(){
^
Interpreter Error: 而在第3牢房中:
using namespace std;
cout << "using std" << endl;给予:
using std然后,在第4和第5单元中:
void f2(){
cout << "HI, still using std.\n";
}
f2();幸福地给予:
HI, still using std.有什么解释可以解释希埃夫-巴茨在细胞间的作用吗?如何解释C++ (在较高的用户级别上)?我在这里没有看到任何关于这个问题的讨论-- 读博士,或这里。
更多线索:在单元格1中:
void a() {}
void b() {}给出
error: function definition is not allowed here
void b() {}而且似乎每个细胞最多可以定义一个函数,这是希埃夫-依附的一条隐含规则。我们能把这些规则明文规定吗?
另一个bug:
struct A {
A(int);
int i;
};
A::A(int x) : i{x} {}给予:
error: expected '{' or ','
A::A(int x) : i{x} void __cling_Un1Qu31(void* vpClingValue) {但
A::A(int x) { i = x; }被接受了。它实际上是无法接受类成员初始化列表的cling,而xeus-can继承了bug。
但是,在命名空间中包装上面的struct和ctor,不会导致错误:
namespace aa {
struct A {
A(int);
int i;
};
}
namespace aa {
A::A(int x) : i{x} {}
}
aa::A a{3};
a.i打印出3,并给出:
input_line_8:5:2: error: unknown type name 'a'
a.i;在西埃斯喀斯特,除非a.i被移动到一个新的细胞里,在那里它会给3。
发布于 2022-01-24 08:01:58
就像这个链接中给出的解释一样,希埃夫-克鲁是这样工作的:
在以下链接中给出了一些规则:Gotchas.html
如果挂起多次未能编译/计算单元格(此处不允许函数定义,或各种类型错误),内核可能已损坏/处于糟糕的状态,因此只需使用内核->重新启动并运行所有单元。实际上,xeus-that作为一个解释器工作,这就是为什么它在单个单元格中只读取一条指令而不像编译器的原因。
详细信息在以下链接中提供:https://blog.jupyter.org/interactive-workflows-for-c-with-jupyter-fe9b54227d92


https://stackoverflow.com/questions/70748204
复制相似问题