谁可以给我解释一下这个?特别是之间的区别:
http://github.com/whymirror/greg和http://piumarta.com/software/peg/
前者是后者的可重入版本.
我想提高我对reentrant一词的理解.
这个功能是可重入的吗?
function* foo() {
yield 1;
yield 2;
}
Run Code Online (Sandbox Code Playgroud)
还有这个?
function foo() {
return 1;
}
Run Code Online (Sandbox Code Playgroud)
还有这个?
var x = 0;
function foo() {
return x++;
}
Run Code Online (Sandbox Code Playgroud)
还有这个?
function foo() {
setTimeout(foo, 1000);
}
Run Code Online (Sandbox Code Playgroud) 正如标题所说:
如果我有一个带有静态成员函数的类,它本身不包含静态变量,我可以考虑该成员函数可重入吗?
void reverse_string(char* string, int str_size) {
char tmp;
int i = 0;
int j = str_size - 1;
while (i < j) {
tmp = string[i];
string[i] = string[j];
string[j] = tmp;
++i;
--j;
}
}
Run Code Online (Sandbox Code Playgroud)
我认为这个函数是可重入的,因为它不使用任何全局变量.它只修改参数.
我的问题是:这个函数是可重入的吗?如果是的话,我的论点是否足够好?
提前致谢
我是 C++ 新手,想知道什么时候应该使用 new,什么时候不应该使用,例如“int x = 5”或“int * x = new int(5)”。我知道新在堆中保留内存,因此在块结束时不会被删除,但由于保存地址的变量将在块之外变得不可访问,我看不到任何好处。
例子:
if(x) {
int * z = new int(5);
// Do something
}
// At this point the 5 is saved somewhere but since z is unaccessible I can't use it.
Run Code Online (Sandbox Code Playgroud)
补充:这个问题没有重复,因为其他问题只解释了什么是堆,而没有描述它的好处。