segmentation fault in capture

segmentation fault in capture

the following compiles but runs with a seg fault. Anthing wrong?

===============================================
#include
#include

using arbb::i32;

bool condition = true;

// it is fine if data is passed by value only
// void hello(i32 data) {

void hello(i32& data) {
if (condition) {
std::cout << "hello, true!" << std::endl;
} else {
std::cout << "hello, false!" << std::endl;
}
}

int main() {
capture(hello);
return 0;
}

publicaciones de 3 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.

I've seen this before too. I guess its a bug, but if you assign something to data then
all is well.

void hello(i32& data) {
if (condition) {
std::cout << "hello, true!" << std::endl;
} else {
std::cout << "hello, false!" << std::endl;
}
data = 5; // random assignment
}

--
jason

Just as Jason pointed out, if the outgoing parameter was actually assigned inside the function then it would not give seg fault. This is a known problem and we are working on it.

Meanwhile, I'd like to point out that this is really a corner case. Usually, when a function takes an outgoing parameter, you do want to modify it. Otherwise, you should just pass it by value. Another thing to note is, that a valid ArBB function should always take at least one outgoing parameter.

Hope this helps. Thanks.

Zhang

Deje un comentario

Por favor inicie sesión para agregar un comentario. ¿No es socio? Únase ya