我尝试printf从我的汇编代码中使用,这是一个应该打印hello到标准输出的最小示例:
.section .rodata
hello:
.ascii "hello\n\0"
.section .text
.globl _start
_start:
movq $hello, %rdi # first parameter
xorl %eax, %eax # 0 - number of used vector registers
call printf
#exit
movq $60, %rax
movq $0, %rdi
syscall
Run Code Online (Sandbox Code Playgroud)
我用
gcc -nostdlib try_printf.s -o try_printf -lc
Run Code Online (Sandbox Code Playgroud)
当我运行它时,它似乎工作:字符串hello被打印出来,退出状态是0:
XXX$ ./try_printf
hello
XXX$ echo $?
0
XXX$
Run Code Online (Sandbox Code Playgroud)
但是当我尝试捕获文本时,很明显,某些内容无法正常工作:
XXX$ output=$(./try_printf)
XXX$ echo $output
XXX$
Run Code Online (Sandbox Code Playgroud)
该变量output应具有 value hello,但为空。
我的用法有printf什么问题?
当我打开捆绑时,除了我的 angular.js 文件外,所有东西都会捆绑并正确缩小。
我收到以下错误:
“缩小失败。返回未缩小的内容。(173,115-122):运行时错误JS1019:循环外不能有'break':break a”
但是它似乎返回了一个缩小的结果并且该站点没有加载。
我尝试将文件更新为 angular 1.5.8,并尝试捆绑 .min.js 文件但没有成功。
我试图将以下用 C++ 编写的声明包装在 cython 中:
template<typename T, double (*distance)(const DataPoint&, const DataPoint&)>
class VpTree
{...}
Run Code Online (Sandbox Code Playgroud)
我还在 C++ 中得到了以下定义:
inline double euclidean_distance(const DataPoint &t1, const DataPoint &t2) {...}
Run Code Online (Sandbox Code Playgroud)
我正在尝试将其包装在 cython 中。这是我根据文档得出的结论:
cdef extern from "vptree.h":
# declaration of DataPoint omitted here
cdef inline double euclidean_distance(DataPoint&, DataPoint&)
cdef cppclass VpTree[T, F]: # F is almost certainly wrong
...
Run Code Online (Sandbox Code Playgroud)
并围绕它构建一个包装器:
cdef class VPTree:
cdef VpTree[DataPoint, euclidean_distance] tree
def __cinit__(self):
self.tree = VpTree[DataPoint, euclidean_distance]()
Run Code Online (Sandbox Code Playgroud)
不幸的是,这会导致以下错误:
------------------------------------------------------------
cdef class VPTree:
cdef VpTree[DataPoint, euclidean_distance] tree
^ …Run Code Online (Sandbox Code Playgroud) 当我对以下 Cython 模块进行 cythonize 时
%%cython
cdef double *ptr=[1,2,3]
print(ptr)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误消息:
无法将“double *”转换为 Python 对象
但是,以下 Cython 模块:
%%cython
cdef double val=0.0
print(val)
Run Code Online (Sandbox Code Playgroud)
cythonized 没有问题。
任何其他指针类型(即int *,float *等等)也会出现此问题。
我有一个函数,我试图返回一个数字和一个整数向量。我拥有的是
cdef func() nogil:
cdef vector[int] vect
cdef int a_number
...
return a_number, vect
Run Code Online (Sandbox Code Playgroud)
但这会产生像Assignment of Python object not allowed without gil. 有解决方法吗?
根据Cython文档,我编写了以下cython代码如下:
\n\nIn [1]:%load_ext Cython\nIn [2]: %%cython\n from libcpp.vector cimport vector\n\xe2\x80\x8b cdef vector[int] *vec_int = new vector[int](10)\nRun Code Online (Sandbox Code Playgroud)\n\n编译后,ipython产生以下错误:
\n\nError compiling Cython file:\n------------------------------------------------------------ \n... \nfrom libcpp.vector cimport vector \ncdef vector[int] *vec_int = new vector[int](10) \n ^ \n------------------------------------------------------------\n/Users/m/.ipython/cython/_cython_magic_a72abb419ccf1b31db9a1851b522a4bf.pyx:3:32: Operation only allowed in c++\nRun Code Online (Sandbox Code Playgroud)\n\n我的代码有什么问题吗?
\n三规则是众所周知的,并且如果必须定义析构函数,那么最有可能定义一个复制构造函数和赋值运算符.
但是,最近在一些代码中,我偶然发现了一个"二阶规则":只定义了析构函数和复制构造函数,并让assign运算符留给编译器定义.我的第一个想法是"这肯定是一个错误",但现在我不确定,因为所有编译器(gcc,msvs,intel)都生成了赋值操作符,它调用了复制构造函数.
简化后,该类如下所示:
struct A{
size_t size;
int *p;
A(size_t s): size(s), p(new int[size]){}
A(const A&a): size(a.size), p(new int[size]){
std::copy(a.p, a.p+a.size, p);
std::cout<<"copy constructor called\n";
}
~A(){
delete[] p;
}
};
Run Code Online (Sandbox Code Playgroud)
像这样使用:
int main(){
A a(2);
a.p[0]=42.0;
A b=a;
std::cout<<"first: "<<b.p[0]<<"\n";
}
Run Code Online (Sandbox Code Playgroud)
产生以下输出:
copy constructor called
first: 42
Run Code Online (Sandbox Code Playgroud)
我的问题:保证,编译器定义的赋值运算符将调用复制构造函数,或者只是一个幸运的巧合,所有编译器都这样做?
编辑:这是真的,我混淆了初始化和分配!更换A b=a;的A b(0); b=a导线如预期的双重释放错误.
我对Clojure很新,并且问自己,如何定义/扣除匿名函数的arity.
请考虑以下穷人count功能:
(reduce #(+ 1 %1) 0 '(1 2 3 55))
Run Code Online (Sandbox Code Playgroud)
使用clojure运行它我收到以下错误消息:
ArityException args(2)的错误数量传递给:user/eval1157/fn - 1158 clojure.lang.AFn.throwArity(AFn.java:429)
但是,它适用于JavaScript-Clojure并4根据需要返回(您可以在此处执行命令).
通过交换改变命令%1- > %2到
(reduce #(+ 1 %2) 0 '(1 2 3 55))
Run Code Online (Sandbox Code Playgroud)
将在两个版本上编译(但不再起作用count).在这种情况下,似乎可以推断出%2至少有两个论点.
那么哪个版本的Clojure是对的?我是否允许向通过#(...)此函数内部定义的匿名函数提供任意数量的参数?
它应该被认为是JavaScript-Clojure中的错误吗?
编辑:正如在评论和答案中所解释的那样,这就是JavaScript的工作方式.有对Java的Clojure的,这是记录在案的差异在这里,特别是:
调用fn时,当前没有运行时强制执行arity
Cpython优化字符串增量操作,在为字符串初始化内存时,程序为其留下额外的扩展空间,因此,在递增时,原始字符串不会复制到新位置.我的问题是为什么字符串变量的id会发生变化.
>>> s = 'ab'
>>> id(s)
991736112104
>>> s += 'cd'
>>> id(s)
991736774080
Run Code Online (Sandbox Code Playgroud)
为什么string变量的id改变了.
我正在尝试安装 pyclipper 以与 nototools 一起使用。https://github.com/googlefonts/nototools但我无法安装 pyclipper。我认为 Visual Studio 构建工具有一些东西。
Collecting pyclipper==1.1.0.post1
Using cached pyclipper-1.1.0.post1.zip (135 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Building wheels for collected packages: pyclipper
Building wheel for pyclipper (PEP 517) ... error
ERROR: Command errored out with exit status 1:
command: 'c:\users\phuwi\appdata\local\programs\python\python39\python.exe' 'c:\users\phuwi\appdata\local\programs\python\python39\lib\site-packages\pip\_vendor\pep517\_in_process.py' build_wheel 'C:\Users\phuwi\AppData\Local\Temp\tmpwa7t8eac'
cwd: C:\Users\phuwi\AppData\Local\Temp\pip-install-ejg_l8me\pyclipper_be85d240fbf84e1388f6c535a16010eb
Complete output (26 lines):
Distribution mode: Compiling Cython generated .cpp sources.
running bdist_wheel
running build
running …Run Code Online (Sandbox Code Playgroud)