LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

"sizeof" problem

Solved!
Go to solution
void UDPchannelsend(uint8_t* msg_to_send)
{
int error = 0;
int *msg;
//uint8_t size = sizeof(uint8_t *);
//uint8_t msg[40];
msg= (int*)calloc(sizeof(msg_to_send), sizeof(int));
memcpy(msg,msg_to_send,sizeof(msg_to_send));

errChk(UDPWrite (wholePODchannel, UDPwritePort, UDP_DestAddress, msg, sizeof(msg)));
free (msg);
Error:
if (error < 0)
MessagePopup("Error", GetGeneralErrorString(error));
}

hey,

i'm getting some problems with "sizeof" in the calloc func.

i'm trying to create a generic UDPSend function, with a pointer to array argument, but with no luck.
my msg_to_send is 34 bytes (i can verify in the watch expression), but my "msg" after the calloc is only 4 bytes.

i tried to check the size that "sizeof" is giving, and hence the line:

uint8_t size = sizeof(uint8_t *);

 no matter what type i insert in the brackets, i always get " 4 ".

any thoughts?




 

0 Kudos
Message 1 of 3
(2,629 Views)
Solution
Accepted by topic author alon9669

The size of a pointer and the size of what it points to are not related. For 32 bit code, pointers consume 32 bit, i.e., 4 bytes, as you found out Smiley Wink

0 Kudos
Message 2 of 3
(2,615 Views)

thank you for the reply.

i changed my receiving function to get 2 arguments, which the size of the array is one them,
and it worked.

0 Kudos
Message 3 of 3
(2,608 Views)