Software Archive
Read-only legacy content
17060 Discussions

Problem with array-notation in a function

leifblaese
Beginner
1,691 Views
Hi,
i recently read about the Arraynotation in Cilk and tried to devise a test function of my own: I have an array of length 10, filled with ones and want to change that to twos.
Now, when i do that in my main()-function using array notation it's not a problem. However, if i declare my own function and use the array as a parameter, i get a compiler error saying
arraynotation.cpp: In function int foo(int*):
arraynotation.cpp:8:4: internal compiler error: Segmentation fault
A[:] = 2;
^
I am not very experienced using cilk/c++ but this seems to me like there is a bug in the compiler. Or is itin generalforbidden to use this arraynotation outside of the main function (which would not make sense). I used Fedora 16 w/ the cilkplus-branch of the gcc; this is the code i used:
[cpp]int foo(int A[10]) { A[:] = 2; return(0); } int main(int argc, char** argv) { int A[10]; A[:] = 1; int b = foo(&A[0]); return 0; }[/cpp]
0 Kudos
5 Replies
Balaji_I_Intel
Employee
1,691 Views
Hello Leifblase,
In GCC, to use the ":" syntax, the compiler should know the size of array to find the length. When you pass Ainto foo, it is getting A as a pointer and that iswhy it is failing.

So, please replace theA[:] = 2 with A[0:10] = 2

Thanks,

Balaji V. Iyer.
0 Kudos
leifblaese
Beginner
1,691 Views
[cpp] [/cpp] Thank you very much. That was obviously the problem.

When I replaced the code as you suggested, it did not work at first, however. Only after inserting three lines to generate some output (see below) it compiled. Without the for-loop i get a compiler-error saying

array-notation-test.cpp: In function int foo(int*):
array-notation-test.cpp:8:20: internal compiler error: in gimplify_expr, at gimplify.c:7877

I am somewhat confused about this, because the for-loop has obviously nothing to do with the array code. Maybe i will post an answer here when i figure out what exactly happened.

Just to clarify, this works now:

[cpp]int foo(int A[10]) { A[0:10] = 2; for (int i = 0; i < 10; i++) { cout << A; } cout << endl; return(0); } [/cpp]

Thanks,
Leif
0 Kudos
Balaji_I_Intel
Employee
1,691 Views
I am able to reproduce this and I will get back to you as soon as I find a fix. Thank you very much forreporting this bug.

Thanks,

Balaji V. Iyer.
0 Kudos
Balaji_I_Intel
Employee
1,691 Views
Hello Leif,
I have fixed the bug and submitted a patch (http://gcc.gnu.org/ml/gcc-patches/2012-06/msg00317.html). The patch is already checked into Cilkplus gcc.

Thank again!

Balaji V. Iyer.
0 Kudos
leifblaese
Beginner
1,691 Views
Thank you, it works fine now.
0 Kudos
Reply