07-17-2018 11:03 AM
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?
Solved! Go to Solution.
07-17-2018 03:13 PM
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
07-18-2018 01:13 AM
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.