Software Archive
Read-only legacy content
17060 Discussions

declaration error

newport_j
Beginner
738 Views

Igot the following error mesage when I compiled my code with icc.

InitializeScenarioData.c (192) error: Cilk_for initilization must be a declaration

cilk_for ( j = 0; j < (*Env).nz_SSP; j+1 ) {
^

I declared j as an integer. I also am using i (also declared as an integer) it is initialized and declared. Why am I getting this error?

Thanx in advance.

Newport_j
0 Kudos
5 Replies
Barry_T_Intel
Employee
738 Views

Are you coding in C or C++? The C++ dialect of Cilk requires you to declare the loop control variable in the cilk_for statement. ie:

 cilk_for ( int j = 0; j < (*Env).nz_SSP; j+1 ) {

This was done to emphasize that the scope of the loop control variable is limited to within the loop. It was only relaxed for C because we had no choice.

- Barry

0 Kudos
newport_j
Beginner
738 Views


It seems that most if the time you do not have to declare a variable in the for statement in c, but sometimes it does require you to. I can think of no other reason that that for this error.

Newport_j

0 Kudos
TimP
Honored Contributor III
738 Views
In OpenMP, some of us prefer to use C99 rather than C89, so that we can define the loop counter in the for() initialization rather than requiring it to be designated as private. For consistency, I personally would prefer the local declaration, not that such reasoning carries any weight.
0 Kudos
SergeyKostrov
Valued Contributor II
738 Views
Quoting newport_j
...It seems that most of the time you do not have to declare a variable in the for statement in C...

That depends on a C/C++compiler andsupported version of aC/C++ LanguageStandard.

Please take a look at two genericcases:

// Case 1 - Variable 'i' isdeclared in each 'for'statement.For some legacy C/C++compilersitwill be a
compilation error.

...
int iArray[32];

for( int i = 0; i < 32; i++ )
iArray = i;

for( int i = 0; i < 32; i++ )
iArray++;
...

// Case 2 - Variable 'i' is declared outside of both'for' statements. In that case the code could be
successfully compiled with legacy and modern C/C++compilers.These are more
portablecodes.

...
int i;
int iArray[32];

for( i = 0; i < 32; i++ )
iArray = i;

for( i = 0; i < 32; i++ )
iArray++;
...

Both cases implement the same logic.
0 Kudos
Barry_T_Intel
Employee
738 Views
If you give me a complete program that reproduces the problem, we can look at whether this is a bug or a misunderstanding. At this point I don't have enough information to tell.

- Barry
0 Kudos
Reply