Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Vishnu
Novice
61 Views

Error assigining dependent value to variable at file scope

I want to make a few read-only variables, at file-scope. A couple of them are dependent on other such variables. A sample code is as follows: static const double A = 1.0; static const double B = A/5; int main(){} Compiling this gives me the error: expression must have a constant value But GCC does not complain. Is this a bug in ICC, or is it GCC that isn't standard compliant? Is this relevant: ? https://software.intel.com/en-us/forums/intel-c-compiler/topic/286645
0 Kudos
4 Replies
Viet_H_Intel
Moderator
61 Views

 

I've tried GCC 4.8.3, 6.3.0 and 7.3.0. They all gave an error as seen below:

vahoang@orcsle147:/tmp$ gcc t.c -c
t.c:3:25: error: initializer element is not constant
 static const double B = A/5;
                         ^
vahoang@orcsle147:/tmp$ cat t.c
#include<stdio.h>
static const double A = 1.0;
static const double B = A/5;
int main(){}

vahoang@orcsle147:/tmp$ icc t.c -c
t.c(3): error: expression must have a constant value
  static const double B = A/5;
                          ^

 

Vishnu
Novice
61 Views

Viet Hoang (Intel) wrote:
I've tried GCC 4.8.3, 6.3.0 and 7.3.0. They all gave an error as seen below:
I'm using GCC 8.2.1
Viet_H_Intel
Moderator
61 Views

 

The test passed when compile with -Tp

tmp$ icpc  -Tp t.c -c
tmp$ 

Viet_H_Intel
Moderator
61 Views

 

That's a workaround. I've filed an internal bug against ICC. The tracker number is: CMPLRIL0-30632

Thanks,

Viet 

Reply