Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

get_environment_variable bug

Davis__John
Beginner
142 Views

I believe that the get_environment_variable subroutine has a bug

bash-4.1$ uname -a
Linux mars 2.6.32-696.18.7.el6.x86_64 #1 SMP Thu Jan 4 17:31:22 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
bash-4.1$ /opt/intel/bin/ifort -v
ifort version 16.0.0
bash-4.1$ cat test.f90
program test
 integer :: v

 call get_environment_variable ("TG_NO_HE5_OUTPUT", status=v)
 write (*,*) 'status=', v
end program
bash-4.1$ /opt/intel/bin/ifort -w ./test.f90
bash-4.1$ TG_NO_HE5_OUTPUT= ./a.out
status= 1
bash-4.1$ TG_NO_HE5_OUTPUT=foo ./a.out
status= 0

The documentation for get_environment_variable suggests that status=0 should be returned for both cases.

0 Kudos
1 Solution
Steve_Lionel
Black Belt Retired Employee
142 Views

I tend to agree with you that "exists but has no value" should return a status of zero. Please report this to the Online Service Center.

View solution in original post

4 Replies
Steve_Lionel
Black Belt Retired Employee
142 Views

I've rewritten this response four times already...

I guess there is some ambiguity regarding whether the variable exists with no value, or doesn't exist, in the first case. I note that F2018 adds words " or the VALUE argument is not present" to the zero case - F2008 doesn't say that. 

I am not a bash expert, but the documentation I can find suggests that "unset" is needed to make the variable not exist at all.

Davis__John
Beginner
142 Views

Please consider the following:

bash-4.1$ TG_NO_HE5_OUTPUT= printenv | grep TG_NO_HE5_OUTPUT
TG_NO_HE5_OUTPUT=

This shows that the variable exists but has no value, or equivalently, has the value of the empty string "".

Also, here is the C equivalent:

bash-4.1$ cat t.c
#include 
#include 
int main (int argc, char **argv)
{
   (void) argc; (void)argv;
   (void) fprintf (stdout, "status = %d\n",
                   (NULL == getenv ("TG_NO_HE5_OUTPUT")));
   return 0;
}
bash-4.1$ gcc -W -Wall t.c
bash-4.1$ ./a.out
status = 1
bash-4.1$ TG_NO_HE5_OUTPUT= ./a.out
status = 0
bash-4.1$ TG_NO_HE5_OUTPUT=foo ./a.out
status = 0

This also shows that an environment variable can exist with no value.

Thanks, --John

 

Steve_Lionel
Black Belt Retired Employee
143 Views

I tend to agree with you that "exists but has no value" should return a status of zero. Please report this to the Online Service Center.

View solution in original post

Devorah_H_Intel
Moderator
142 Views

Yes, John, please submit a bug report via https://supporttickets.intel.com/?lang=en-US . We appreciate your taking your time in reporting this.

Reply