03-13-2018 02:20 AM
Hi,
I have a 1D Array which is having a hex data in it. I have int pointer as a structure element which should get the memory address of array. (Pointer points to my 1D array in c code).
How can I implement that in labVIEW?
Solved! Go to Solution.
03-13-2018 02:43 AM - edited 03-13-2018 02:45 AM
03-13-2018 03:12 AM - edited 03-13-2018 03:21 AM
Your language is not very clear. Is your pointer stored in an int variable inside the structure (which would be BAAAD and non 64 bit compatible) or is it a pointer to an int? I can only echo Gerd's remark: Show your codes!
It is beyond me how people expect to get useful help in programming problems from two lines of vaguely formulated prosa about their problem. To my knowledge, nobody on this forum has magic mind reading capabilities to correctly guess what your problem might be.
And yes when posting VI code, please do a save for previous and save it for at least 2 versions earlier than the current version since not everyone has the luxury to install the latest and greatest version of LabVIEW on his work machine. You do want to increase the chance for people to be able to look at your code, as it benefits you! I and many others on this fora do this voluntarily and have their regular work to do besides this, so I simply stopped to bother about most posts that make me jump through hoops in order to even try to help.
03-13-2018 04:47 AM
I'm assuming you're talking about
struct {
something
something
int* Array[]
}
In LabVIEW it'd be a cluster with [Something, Something, Int Array].
Whenever you use the Array wire, it uses a pointer internally, you just can't/shouldn't use/access it.
/Y
03-13-2018 08:14 AM
And I would add to that: Clean up your VIs before you post them.
When someone asks for help and posts a VI with a messy block diagram, I generally ignore it.
03-13-2018 10:00 AM - edited 03-13-2018 10:01 AM
SNP@25 wrote:
Hi,
I have a 1D Array which is having a hex data in it. I have int pointer as a structure element which should get the memory address of array. (Pointer points to my 1D array in c code).
How can I implement that in labVIEW?
I don't understand why you would need to know the memory location. Why does it even matter where the array is stored in memory?
LabVIEW abstract the need for such low level access like memory locations and pointers.
03-13-2018 04:32 PM
@paul_cardinale wrote:
And I would add to that: Clean up your VIs before you post them.
When someone asks for help and posts a VI with a messy block diagram, I generally ignore it.
A messy block diagram is like text code with random indents. The compiler won't care, but I'd look the other way if the next developer to take over your code went and strangled you. 😉
03-14-2018 08:40 AM - edited 03-14-2018 08:55 AM
Hi,
Thank you for your kind gesture GerdW.
Code is as below:
typedef struct
{
void * ExtraDataPtr;
} msg;
unsigned char iDataBytes[]={0,1,2,3,4,5,6,7,8,9,10};
msg.ExtraDataPtr = &iDataBytes;
I have defined this 'msg' structure in labVIEW using 'Cluster'. I have iDataBytes 1-D array also created in my VI.
Now I am willing to implement msg.ExtraDataPtr = &iDataBytes this in LabVIEW.
Regards,
S.
03-14-2018 08:53 AM
03-14-2018 09:35 AM
If the code is as below this will definitely not work!
typedef struct { void * ExtraDataPtr; } MessageRecord; int MyFunnyFunc(MessageRecord *msg) { unsigned char iDataBytes[]={0,1,2,3,4,5,6,7,8,9,10}; msg->ExtraDataPtr = &iDataBytes;
}
iDataBytes is allocated on the stack when entering the function and the stack is cleaned up when leaving the function making the memory iDataBytes uses undefined at the time your function returns to LabVIEW.
If iDataBytes is instead a global static variable outside any function then this would not be the case but it is pretty cumbersome and problematic to return pointers like this to any caller, not just LabVIEW alone.
Better would be to do something like this:
static unsigned char iDataBytes[]={0,1,2,3,4,5,6,7,8,9,10};
int MyFunnyFunc(unsigned char *buffer, int *length) {
if (maxLength > sizeof(iDataBytes))
maxLength = sizeof(iDataBytes))
memcpy(buffer, iDataBytes, maxLength);
return maxLength;
}
Working safely with pointers that are passed across domain borders (LabVIEW<->C runtime) is very tricky and error prone so it is better to simply use the standard C model where the caller provides all the buffers necessary and the callee fills them accordingly.