LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to declare a pointer to structure element which is array structures

Solved!
Go to solution

 LStr, *LStrPtr, **LStrHandle structure is taken from LabView cintools extcode.h
 
   I used: sprintf(((*(*in_array)->Strings[*count])->str), local_str); to pass local_str string to
LabView array.  It worked fine, but  one programmer adviced me to change code to  be more readable.
Means - to change  (*(*in_array)->Strings[*count]) construction to a pointer. I tried many different
ways to implement this - but in all cases it caused LabView to crash. I understand that this question
is related to C programming not about LabView, but could you point me at a place where I have mistake ?
The most likely incorrect string is " LV_array = &(**((**in_array).Strings[*count])); "
 
Thanks in advance.

 

 

 

1.  typedef struct {
2.        int32   cnt;            /* number of bytes that follow */
3.        uChar   str[1];         /* cnt bytes */
4.  } LStr, *LStrPtr, **LStrHandle;
5.      
6.  typedef struct {
7.        int32 dimSize;
8.        LStrHandle Strings[1];
9.  } LVStringArray;
10.      
11. typedef LVStringArray **LVStrArrayHdl;
12.      
13  _declspec(dllexport) void avg_hello(int *count, LVStrArrayHdl in_array)
14.      {
15.      
16.       unsigned char *local_str="Entering function ma_in()";
17.       (*count) = 0;
18.       LStr* LV_array;
19.      
20.       LV_array = &(**((**in_array).Strings[*count])); //Set address to which should point LV_array
21.       subfunc(count, &in_array);                      // Call a function which resizes array (works)
22.       sprintf(LV_array->str, local_str);              //passing string to LabView (not working)
23.      
24. }

0 Kudos
Message 1 of 7
(3,975 Views)

It looks like you're attempting to return the address of 2 defrerences [ $(**... ], have you got a useful error message from a failed build?

_____________________________
- Cheers, Ed
0 Kudos
Message 2 of 7
(3,968 Views)

 by changing so:

 

LStr *LV_array;
LV_array = &(*((**in_array)->Strings));

 

 warning C4047: '=' : 'LStr *' differs in levels of indirection from 'LStrHandle *'

0 Kudos
Message 3 of 7
(3,960 Views)

Have you got the error message from your original attempt?

 

The pointers and dereferences look like they should be correct in your original post. Is that the line the error occurs in?

 

EDIT: Actually, I think you might be missing an * before the LV_array->

Message Edited by yenknip on 10-30-2008 04:31 PM
_____________________________
- Cheers, Ed
0 Kudos
Message 4 of 7
(3,952 Views)

LV_array = &(**((**in_array).Strings[*count]));

 

sprintf(LV_array->str, local_str);  - compiles without warnings, but I get error while running VI

 

 sprintf(*LV_array->str, local_str); causes:

 >: warning C4047: 'function' : 'char *' differs in levels of indirection from 'uChar'

Message Edited by ACiDuser on 10-30-2008 11:54 AM
0 Kudos
Message 5 of 7
(3,934 Views)

Hi,

 

Try this in that way:

 

 

Should be OK.

Complete source in attachment.

 

best regards, 

Andrey.

 

Message Edited by Andrey Dmitriev on 10-30-2008 05:54 PM
Download All
Message 6 of 7
(3,931 Views)
Solution
Accepted by ACiDuser

thank you Andrey Dmitriev! spasibo!

 

With your example I understood where I have error in my code:

I tried to assign to pointer an address of string which wasn't yet pre-allocated!

 

that means simply swapping strings we get final code:

 

 

1.  typedef struct {
2.        int32   cnt;            /* number of bytes that follow */
3.        uChar   str[1];         /* cnt bytes */
4.  } LStr, *LStrPtr, **LStrHandle;
5.      
6.  typedef struct {
7.        int32 dimSize;
8.        LStrHandle Strings[1];
9.  } LVStringArray;
10.      
11. typedef LVStringArray **LVStrArrayHdl;
12.      
13  _declspec(dllexport) void avg_hello(int *count, LVStrArrayHdl in_array)
14.      {
15.      
16.       unsigned char *local_str="Entering function ma_in()";
17.       (*count) = 0;
18.       LStr* LV_array;
19.       subfunc(count, &in_array);                      // Call a function which resizes array (works), First we resize array, and only after that we can assign an address of string to a pointer

20.       LV_array = &(**((**in_array).Strings[*count]));  //Assigning address to which should point LV_array
21.      
22.       sprintf(LV_array->str, local_str);              //passing string to LabView (not working)
23.      
24. }
 

0 Kudos
Message 7 of 7
(3,924 Views)