Problem with casting

The latest netcdf-4.0-alpha was released recently and when I compile it with pgcc, I get test failures that don’t show up when compiled with intel or GNU compilers. I have tried this with both pgcc-5.1-6 and pgcc-6.0-5 on i686. I isolated the problem to a small snippet shown below:

#include <stdio.h>
int main() {
  short shrt, shrt2;
  int value;

  value = 100000;
  shrt = -31072;
  shrt2 = value;
  if (!(shrt == shrt2)) printf("Error 1\n");
  if (shrt != shrt2) printf("Error 2\n");
  if (!(shrt == (short)value)) printf("Error 3\n");
  if (shrt != (short)value) printf("Error 4\n");

When run, I get the output

sahp6588> pgcc test.c -o test.pgi
sahp6588> ./test.pgi
Error 1
Error 3
Error 4

When compiiled and run with intel-8.1, intel-9.0, and gcc-3.4.5, gcc-4.1.0, I get no output.

Anyone see what I am doing wrong?

Hi GSj,

Add “-Msignextend” to your compilation.

% pgcc tmp.c
% a.out
Error 1
Error 3
Error 4
% pgcc tmp.c -Msignextend
% a.out
  • Mat