AngelHunter Posted April 27, 2006 Report Share Posted April 27, 2006 i have a const double array, and when i want to copy a value, for example: typedef struct { double x, y, z} array3; const array3* v; double my_value; my_value = v->x; and labview crashes, and the debug window shows this line as the cause. with some access violation error messages.... anybody encountered something like this? please help me... thank you! Quote Link to comment
David Boyd Posted April 28, 2006 Report Share Posted April 28, 2006 OK, it's been awhile since I even HAD a C compiler installed on my PC, but here goes: i have a const double array, and when i want to copy a value, for example: typedef struct { double x, y, z} array3; // you've defined 'array3' to mean a structure containing three double-precision floating-point elementsconst array3* v; // you've instanciated a pointer to a constant 'array3' and named the pointer 'v'double my_value; // you've instanciated a double-precision floating-point named 'my_value'my_value = v->x; // you tried to assign to 'my_value' the value of the 'x' element of the struct pointed to by 'v'// ... but you never assigned 'v' a value (i.e., reserved memory for an 'array3' and pointed 'v' at it) and labview crashes, (looks like you tried to dereference a null pointer) and the debug window shows this line as the cause. with some access violation error messages.... anybody encountered something like this? please help me... thank you! Did I get it right?? Hope this helps, Dave Quote Link to comment
Rolf Kalbermatter Posted May 9, 2006 Report Share Posted May 9, 2006 i have a const double array, and when i want to copy a value, for example:typedef struct { double x, y, z} array3; const array3* v; double my_value; my_value = v->x; and labview crashes, and the debug window shows this line as the cause. with some access violation error messages.... anybody encountered something like this? please help me... thank you! By declaring "const array3* v;" you only declare a const pointer to the struct but do not allocate any storage for that structure at all. So when you try to dereference that pointer it points into nirwana and crashes. What you want to do is more along the lines of: typedef struct { double x, y, z} array3; const array3 v; double my_value; my_value = v.x; Which of course is still not very useful since v.x will contain some random data (usually 0 but not all compilers will initialize const data to 0). Rolf Kalbermatter Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.