LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CVI compiler problem: static __int64 in expression causes GPF

There appears to be a significant error in the CVI compiler's handling of the __int64 data type.

If an __int64 variable of static storage class is used in an expression, a GPF (general protection fault) will occur at runtime.

       __int64 a;
static __int64 b;
       __int64 c;
       __int64 * pInt64 = malloc (sizeof (__int64))
      
   *pInt64 = 4;

   a = 1;
   b = 2;
   c = a + b;  <============ GPF when this expression is evaluated.
   c = a + *pInt64;  <======  properly evaluates
   b = c + a;   <========properly evaluates

NI needs to fix this.  It's broken in both CVI 7.1 and 8.0.1 





0 Kudos
Message 1 of 4
(3,545 Views)

Hello,

 

This does indeed to be a problem to me.  I have created an error report and sent it to our CVI R&D department for them to investigate (CAR number 3YJDRG3A).

 

I worked off your example and created another example that demonstrates that this problem only occurs when the static local is on the RHS of the ‘+’.  It also works OK when the variable is declared as a module global:

#include <ansi_c.h>
#include <cvirte.h>

static __int64 module_global;

int main (int argc, char *argv[])
{
            __int64 a;
     static    __int64 b;
             __int64 c;
            __int64 d;
               __int64 * pInt64 = malloc (sizeof (__int64));

   a = 1;
   b = 2;
   c = 3;
   *pInt64 = 4;
  
   d = a + b;  //GPF - static local var is used on RHS of '+' operator
   d = b + a;  //OK
  
   d = a + module_global; //ok
   d = module_global + a; //ok
  
   d = a + c;
   d = c + a;
  
   c = a + *pInt64;  //ok
   b = c + a;   //ok

    return 0;
}

 

At any rate, I do apologize for any problems this may have caused you (as debugging a subtle error like this could take a long time), and I hope that we can find a way to work around the problem.

 

Thanks for posting!

Travis M
LabVIEW R&D
National Instruments
0 Kudos
Message 2 of 4
(3,536 Views)
I spent a full day tracking this down.   Not something you'd expect in a product that costs $2k / seat.  Looks like the problem's been there for years.
 
Tell your buddies to get a C99 compiler for CVI while they're at it.    It'll come with full __int64 support, as well as have a whole host of other features that are problematic to deal with in C89.
 
A work around is to malloc the storage and save the pointer as a static.  It looks like the static pointer can be dereferenced all OK anywhere in an expression.
 
Menchar
0 Kudos
Message 3 of 4
(3,533 Views)

Hello Menchar,

 

Again, I sincerely apologize for the trouble this undoubtedly caused!  As programmers we would like to assume that the compiler is completely free of problems.  If we make this assumption, then, when we encounter crashes we naturally assume that it’s our code (and 99.99999999% we’re right) and begin debugging from there.  When the compiler is to blame it leads to frustrating debugging like you surely experienced yesterday.  I linked this post to the bug report filed, so the developers will see your request.  You are also welcome to submit your own product suggestion that goes directly to our R&D department.  Feel free to visit http://sine.ni.com/apps/utf8/nicc.call_me and select “product feedback”.

 

Thanks again for pointing out the problem, and apologies for the trouble!

Travis M
LabVIEW R&D
National Instruments
0 Kudos
Message 4 of 4
(3,498 Views)