Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
Announcements
The Intel sign-in experience has changed to support enhanced security controls. If you sign in, click here for more information.
7782 Discussions

Error assigining dependent value to variable at file scope

Vishnu
Novice
206 Views
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
206 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
206 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
206 Views

 

The test passed when compile with -Tp

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

Viet_H_Intel
Moderator
206 Views

 

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

Thanks,

Viet 

Reply