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;
}

3 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione

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

Lascia un commento

Eseguire l'accesso per aggiungere un commento. Non siete membri? Iscriviti oggi